1
我使用屬性和xml文本反序列化xml文件。問題是這些元素具有相同的屬性。所以我總是得到錯誤,我不能在XmlType中有兩個相同的TypeNames。反序列化具有相同屬性的xml元素
我的XML:
<group_id xsi:type="xsd:int">1</group_id>
<name xsi:type="xsd:int">myNameView</name>
而我的C#:
[XmlType(AnonymousType = true, Namespace = "http://www.w3.org/2001/XMLSchema", TypeName = "int")]
[XmlRoot(ElementName = "group_id")]
public class Group_id
{
[XmlAttribute(AttributeName = "type", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Type { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlType(AnonymousType = true, Namespace = "http://www.w3.org/2001/XMLSchema", TypeName = "int")]
[XmlRoot(ElementName = "name")]
public class Name
{
[XmlAttribute(AttributeName = "type", Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
public string Type { get; set; }
[XmlText]
public string Text { get; set; }
}
的問題是在XmlType將屬性的類型名。如果我只用一個TypeName命名一個元素,它將被正確地反序列化。