我想用 XmlSerializer 序列化一个有效的 xml。但我收到了这个错误信息:
“反映属性“描述”时出现错误。---> System.InvalidOperationException:命名空间“ddi:reusable:3_2_dev”中的顶部 XML 元素“描述”引用了不同的类型 System.Collections.Generic.List`1[Opit. Rogatus.DdiObjects.DdiContent] 和 Opit.Rogatus.DdiObjects.DdiContent。使用 XML 属性为元素或类型指定另一个 XML 名称或命名空间.."
我有这个需要序列化的类。并且有一个属性描述,它标记为序列化程序将其重命名为描述。但是由于在可重用命名空间中显然有另一个描述,我得到了一个错误。
xsd 类别:
<xs:complexType name="CategoryType">
<xs:annotation>
<xs:documentation>A description of a particular category or response. OECD Glossary of Statistical Terms: Generic term for items at any level within a classification, typically tabulation categories, sections, subsections, divisions, subdivisions, groups, subgroups, classes and subclasses.</xs:documentation>
</xs:annotation>
<xs:complexContent>
<xs:extension base="r:VersionableType">
<xs:sequence>
<xs:element ref="CategoryName" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="r:Label" minOccurs="0" maxOccurs="unbounded">
<xs:annotation>
<xs:documentation>A display label for the category.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref="r:Description" minOccurs="0">
<xs:annotation>
<xs:documentation>Description/definition of the category. Note that comparison of categories is determined by the Definition rather than the Label. For example, while the Definition of a Chemist in London and a Pharmacist in New York is the same and comparable, the definitions of Chemist in each location differ significantly and are NOT comparable</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref="r:ConceptReference" minOccurs="0">
<xs:annotation>
<xs:documentation>Reference to a defining concept.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element ref="Generation" minOccurs="0">
<xs:annotation>
<xs:documentation>Generation/derivation details of the category.</xs:documentation>
</xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="missing" type="xs:boolean" use="optional">
<xs:annotation>
<xs:documentation>Indicates if the category contains missing data or not.</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:extension>
</xs:complexContent>
[XmlRoot(ElementName = "Category", Namespace = LogicalProductNamespace)]
public class DdiCategory : AbstractVersionable
{
[XmlElement(ElementName = "CategoryName")]
public List<DdiName> CategoryNames { get; set; }
[XmlArray(ElementName = "Description", Namespace = ReusableNamespace)]
[XmlArrayItem(ElementName = "Content", IsNullable = false)]
public List<DdiContent> Descriptions { get; set; }
[XmlAttribute(AttributeName = "missing")]
public bool Missing { get; set; }
public DdiCategory()
{
Type = DomainObjectType.Category;
Descriptions = new List<DdiContent>();
}
}
可重用的命名空间:
显然,问题在于这两种描述的模糊性。我试图弄清楚如何使用 xml 属性解决它,但到目前为止还没有运气。
如果有人有想法,请随时分享=)
干杯!