0

現在、CityGML (デ) シリアライザーに取り組んでいます - 特定の対応するオブジェクトに C# クラスが必要です - System.Xml.Serialization.XmlSerializer インスタンスに必要なルート クラスに問題があります。ここにいる全員が CityGML にどれほど精通しているかはわかりませんが、ここで状況を説明します。クラスの作成方法についても説明しました。これをスキップしたい場合は、/ /* マークから読み始めることができます。

CityGML は複数の .xsd ファイルで構成され、それぞれが特定のタイプの要素 (appearance.xsd、transports.xsd、building.xsd、vegetation.xsd など) を記述するモジュールであり、ルート ファイル CityGML.xsd も含まれます。ご想像のとおり、各モジュールにはこのルート ファイルの要素が必要です。また、CityGML は実際には GML から多くを継承しているため、GML .xsd ファイルからのインポートも必要です。

これまでのところ、C# クラスの生成に関して、従来の xsd.exe を使用する 2 つの方法を試しました。 - 必要なすべての CityGML クラスを含む単一の .cs ファイルを作成する - 単一のコマンド ライン:

xsd gml/feature.xsd gml/xlinks.xsd gml/geometryBasic2d.xsd gml/geometryComplexes.xsd gml/geometryPrimitives.xsd gml/smil20.xsd
    gml/smil20-language.xsd citygml/xAL.xsd citygml/appearance.xsd citygml/building.xsd citygml/cityFurniture.xsd citygml/cityObjectGroup.xsd
    citygml/generics.xsd citygml/landUse.xsd citygml/relief.xsd citygml/texturedSurface.xsd citygml/transportation.xsd citygml/vegetation.xsd
    citygml/waterBody.xsd citygml/CityGML.xsd citygml/cityGMLBase.xsd /classes /fields /namespace:CityGML

- the creation of a .cs file for each of the CityGML modules - one command line for each module:

xsd citygml/xAL.xsd /classes /namespace:xAL /o:out

xsd gml/feature.xsd citygml/xAL.xsd gml/geometryAggregates.xsd gml/xlinks.xsd
citygml/cityGMLBase.xsd /classes /namespace:CityGMLBase /o:out

xsd gml/feature.xsd citygml/cityGMLBase.xsd citygml/xAL.xsd gml/geometryAggregates.xsd
gml/xlinks.xsd citygml/appearance.xsd /classes /namespace:CityGMLAppearance /o:out

xsd gml/feature.xsd citygml/cityGMLBase.xsd citygml/xAL.xsd gml/geometryAggregates.xsd gml/xlinks.xsd citygml/building.xsd /classes /namespace:CityGMLBuilding /o:out

xsd gml/feature.xsd citygml/cityGMLBase.xsd citygml/xAL.xsd gml/geometryAggregates.xsd gml/xlinks.xsd citygml/cityFurniture.xsd /classes /namespace:CityGMLCityFurniture /o:out

xsd citygml/cityGMLBase.xsd gml/feature.xsd gml/xlinks.xsd citygml/xAL.xsd gml/geometryAggregates.xsd citygml/cityObjectGroup.xsd /classes /namespace:CityGMLCityObjectGroup /o:out

xsd gml/feature.xsd citygml/cityGMLBase.xsd citygml/xAL.xsd gml/geometryAggregates.xsd gml/xlinks.xsd citygml/generics.xsd /classes /namespace:CityGMLGenerics /o:out

xsd gml/feature.xsd citygml/cityGMLBase.xsd citygml/xAL.xsd gml/geometryAggregates.xsd gml/xlinks.xsd citygml/landUse.xsd /classes /namespace:CityGMLLandUse /o:out

xsd citygml/cityGMLBase.xsd citygml/xAL.xsd gml/xlinks.xsd citygml/cityFurniture.xsd gml/coverage.xsd citygml/relief.xsd /classes /namespace:CityGMLRelief /o:out

xsd gml/feature.xsd citygml/cityGMLBase.xsd citygml/xAL.xsd gml/geometryAggregates.xsd gml/xlinks.xsd citygml/texturedSurface.xsd /classes /namespace:CityGMLTexturedSurface /o:out

xsd gml/feature.xsd citygml/cityGMLBase.xsd citygml/xAL.xsd gml/geometryComplexes.xsd gml/xlinks.xsd citygml/transportation.xsd /classes /namespace:CityGMLTransportation /o:out

xsd gml/feature.xsd citygml/cityGMLBase.xsd citygml/xAL.xsd gml/geometryAggregates.xsd 
gml/xlinks.xsd citygml/vegetation.xsd /classes /namespace:CityGMLVegetation /o:out

xsd gml/feature.xsd citygml/cityGMLBase.xsd citygml/xAL.xsd gml/geometryAggregates.xsd gml/xlinks.xsd citygml/waterBody.xsd /classes /namespace:CityGMLWaterBody /o:out

各コマンドについて、最後の .xsd は目的のモジュールであり、その他は必要なインポートです。

残念ながら、xsd.exe は他の .xsd ファイルからのインポートを処理し、インポートされたファイルからだけでなく、必要なファイルのクラスを作成しますが、これらのクラスすべてを 1 つの .cs ファイルにスタックして、これを非常に「直接」行います。どうやら、異なる .cs ファイル内のインポートされたクラスから目的のクラスを分離する方法はありません。したがって、私の最初の質問は、インポートされた .XSD ファイルを処理し、特定の .CS ファイル階層を作成する、XSD.EXE に類似した (デ) シリアル化ツールはありますか? これにより、たとえば、上記のすべてのモジュール .cs ファイルで feature.xsd のクラスの繰り返しが回避されます。

/ /*

次に進むと、実際に問題を引き起こしている問題は XmlSerializer インスタンスに関連しています。これは、階層全体のルート クラスでもある基本の CityGML オブジェクト タイプである CityModelType が完全に有効ではないため、作成できません。

System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(CityModelType));

この割り当ては、最初に XmlTextAttribute を使用して string[] を定義することに関するエラーを引き起こし、CityModelType の「反映」を不可能にしました。XmlTextAttribute を XmlAttributeAttribute に置き換えましたが、その発信元を追跡できなかった現在のメッセージは次のとおりです (はい、フランス語で作業しています)。

System.InvalidOperationException: Impossible de générer une classe temporaire (result=1).
error CS0030: Impossible de convertir le type 'CityGML.LineStringSegmentType[]' en 'CityGML.LineStringSegmentType'
error CS0030: Impossible de convertir le type 'CityGML.LineStringSegmentType[]' en 'CityGML.LineStringSegmentType'
error CS0030: Impossible de convertir le type 'CityGML.LineStringSegmentType[]' en 'CityGML.LineStringSegmentType'
error CS0029: Impossible de convertir implicitement le type 'CityGML.LineStringSegmentType' en 'CityGML.LineStringSegmentType[]'
error CS0029: Impossible de convertir implicitement le type 'CityGML.LineStringSegmentType' en 'CityGML.LineStringSegmentType[]'
error CS0029: Impossible de convertir implicitement le type 'CityGML.LineStringSegmentType' en 'CityGML.LineStringSegmentType[]'

まず、LineStringSegmentType の唯一の発生は曲線に関連しており、.gml ファイルでは使用していません。それらは次のように定義されます。

    public partial class LineStringSegmentType : AbstractCurveSegmentType {

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("coordinates", typeof(CoordinatesType))]
        [System.Xml.Serialization.XmlElementAttribute("pointProperty", typeof(PointPropertyType))]
        [System.Xml.Serialization.XmlElementAttribute("pointRep", typeof(PointPropertyType))]
        [System.Xml.Serialization.XmlElementAttribute("pos", typeof(DirectPositionType))]
        [System.Xml.Serialization.XmlElementAttribute("posList", typeof(DirectPositionListType))]
        [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
        public object[] Items;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("ItemsElementName")]
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public ItemsChoiceType2[] ItemsElementName;

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public CurveInterpolationType interpolation;

        /// <remarks/>
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool interpolationSpecified;

        public LineStringSegmentType() {
            this.interpolation = CurveInterpolationType.linear;
        }
    }

...そして、それらはここで使用されます:

public partial class TinType : TriangulatedSurfaceType {

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayItemAttribute("LineStringSegment", typeof(LineStringSegmentType), IsNullable=false)]
    public LineStringSegmentType[][] stopLines;

    /// <remarks/>
    [System.Xml.Serialization.XmlArrayItemAttribute("LineStringSegment", typeof(LineStringSegmentType), IsNullable=false)]
    public LineStringSegmentType[][] breakLines;

    /// <remarks/>
    public LengthType maxLength;

    /// <remarks/>
    public TinTypeControlPoint controlPoint;
}

...この gml:geometryPrimitives.xsd フラグメントから来ています:

<complexType name="TinType">
    [...]
    <complexContent>
        <extension base="gml:TriangulatedSurfaceType">
            <sequence>
                <element name="stopLines" type="gml:LineStringSegmentArrayPropertyType" minOccurs="0" maxOccurs="unbounded">
                    [...]
                </element>
                <element name="breakLines" type="gml:LineStringSegmentArrayPropertyType" minOccurs="0" maxOccurs="unbounded">
                    [...]
                </element>
                <element name="maxLength" type="gml:LengthType">
                    [...]
                </element>
                <element name="controlPoint">
                    [...]
                    <complexType>
                        <choice>
                            <element ref="gml:posList"/>
                            <group ref="gml:geometricPositionGroup" minOccurs="3" maxOccurs="unbounded"/>
                        </choice>
                    </complexType>
                </element>
            </sequence>
        </extension>
    </complexContent>
</complexType>

<complexType name="LineStringSegmentArrayPropertyType">
    <sequence>
        <element ref="gml:LineStringSegment" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
</complexType>

どこに問題があるのか​​ わかりません。これは非常に奇妙です。ご連絡をお待ちしております。ありがとう。

乾杯、ビクター

4

1 に答える 1