XmlSerializer를 사용하여 유효한 XML을 직렬화하려고합니다. 그러나이 오류 메시지가 나타납니다 :xml 속성을 사용하여 직렬화 모호성을 해결하는 방법은 무엇입니까?
" '설명'속성을 반영하는 동안 오류가 발생했습니다 .-> System.InvalidOperationException : 네임 스페이스 'ddi : reusable : 3_2_dev'의 상위 XML 요소 '설명'이 고유 한 유형을 참조합니다. 시스템 .Collections.Generic.List`1 [Opit.Rogatus.DdiObjects.DdiContent] 및 Opit.Rogatus.DdiObjects.DdiContent. XML 특성을 사용하여 요소에 다른 XML 이름 또는 네임 스페이스를 지정합니다. "
이 클래스는 직렬화 될 필요가있다. 그리고 serializer가 Description으로 이름을 변경하는 것으로 표시된 속성 설명이 있습니다. 하지만 재사용 가능한 네임 스페이스에 다른 설명이 분명히 있기 때문에 오류가 발생했습니다. 카테고리
의 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 속성을 사용하여 해결할 수있는 방법을 찾았으나 지금까지는 아무런 운이 없었습니다.
누구나 아이디어가 있다면 =)
건배!