C# CityGML反序列化问题
我目前正在开发一个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: -创建一个.cs文件,其中包含我需要的所有CityXML类-一个命令行:C# CityGML反序列化问题,c#,xsd.exe,xml-deserialization,gml,C#,Xsd.exe,Xml Deserialization,Gml,我目前正在开发一个CityGML(反)序列化程序——我需要某些对应对象的C#类——我在这方面遇到了一些问题 System.Xml.Serialization.XmlSerializer实例所需的根类。我不知道这里的每个人对CityGML有多熟悉, 但这里是对情况的描述。我还描述了我如何创建我的类,如果你想跳过这个,你可以开始阅读 从//*标记开始: CityGML由几个.xsd文件组成,每个文件都是描述特定类型元素的模块(appearance.xsd、transports.xsd、, build
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
对于每个命令,last.xsd是所需的模块,而其他命令是必需的导入
不幸的是,尽管xsd.exe处理从其他.xsd文件的导入,并且它创建所需文件的类以及从导入的
文件,它非常“直接”地执行此操作,将所有这些类堆叠在一个.cs文件中。显然,没有办法将所需的类分开
来自不同.cs文件中导入的类。
因此,我的第一个问题是,是否有(反)序列化工具,类似于XSD.EXE,用于处理导入的.XSD文件
并创建特定的.CS文件层次结构?这将避免在上述所有模块中重复feature.xsd类
.cs文件
//*
接下来,实际给我带来麻烦的问题与XmlSerializer实例有关,由于基本CityXML
对象类型CityModelType也是整个层次结构中的根类,它不是完全有效的:
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(CityModelType));
该赋值首先产生了一个关于使用XmlTextAttribute定义字符串[]的错误,该字符串呈现CityModelType的“反射”
不可能的。我用XmlAttributeAttribute和当前消息替换了XmlTextAttribute,我无法追踪它们的来源,
这些是(是的,我用法语工作):
首先,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;
}
}
公共部分类LineStringSegmentType:AbstractCurveSegmentType{
///
[System.Xml.Serialization.XmlElementAttribute(“坐标”,typeof(CoordinateType))]
[System.Xml.Serialization.XmlElementAttribute(“pointProperty”,typeof(PointPropertyType))]
[System.Xml.Serialization.XmlElementAttribute(“pointRep”,typeof(PointPropertyType))]
[System.Xml.Serialization.xmlementAttribute(“pos”,typeof(DirectPositionType))]
[System.Xml.Serialization.XmlElementAttribute(“posList”,typeof(DirectPositionListType))]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute(“ItemsElementName”)]
公共物品【】项;
///
[System.Xml.Serialization.XmlElementAttribute(“ItemsElementName”)]
[System.Xml.Serialization.XmlIgnoreAttribute()]
公共项目SchoiceType2[]项目选择名称;
///
[System.Xml.Serialization.XmlAttributeAttribute()]
公共曲线插值;
///
[System.Xml.Serialization.XmlIgnoreAttribute()]
指定的公共布尔插值;
公共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;
}
public分部类TinType:TriangulatedSurfaceType{
///
[System.Xml.Serialization.XmlArrayItemAttribute(“LineStringSegment”,typeof(LineStringSegmentType),IsNullable=false]
公共LineStringSegmentType[]]停止线;
///
[System.Xml.Serialization.XmlArrayItemAttribute(“LineStringSegment”,typeof(LineStringSegmentType),IsNullable=false]
公共LineStringSegmentType[]]特征线;
///
公共长度类型maxLength;
///
公共控制点控制点;
}
…来自此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>
[...]
[...]
[...]
[...]
[...]
我不知道问题出在哪里,这很奇怪。希望很快收到你的来信。谢谢
干杯,
Victor“是否有类似于XSD.EXE的(反)序列化工具,用于处理导入的.XSD文件并创建特定的.CS文件层次结构?”
是的,的确如此,我使用了,这是上帝在我遇到类似问题iwht xsd.exe后送给我的
<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>