如何清理我的 xml 代码
序列化此类的对象后:
[XmlType("Person")] // define Type
public class Person
{
[XmlElement("PropertyType")]
public PropertyType PropertyType { get; set; }
[XmlElement("ID")]
public string ID { get; set; }
[XmlElement("Name")]
public string Name { get; set; }
[XmlElement("City")]
public string City { get; set; }
[XmlElement("Age")]
public Dictionary<object, object> Age { get; set; }
}
我有以下代码:
<PersonenListe>
<PersonenArray>
<PersonObjekt>
<PropertyType>Unknown</PropertyType>
<ID>0</ID>
<FriendlyName>Max Man</FriendlyName>
<City>Capitol City</City>
<Age>33</Age>
<Name>
<item>
<key>
<anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" p8:type="q1:string" xmlns:p8="http://www.w3.org/2001/XMLSchema-instance">test1</anyType>
</key>
<value>
<anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" p8:type="q1:string" xmlns:p8="http://www.w3.org/2001/XMLSchema-instance">test2</anyType>
</value>
</item>
</Name>
</PersonObjekt>
</PersonenArray>
</PersonenListe>
How can I clean up it(I want to have code without this namespaces)? maybe using some attributes?
Update:
when I serialize it separetly I get:
<PersonenListe>
<PersonenArray>
<PersonObjekt>
<PropertyType>Unknown</PropertyType>
<ID>0</ID>
<FriendlyName>Max Man</FriendlyName>
<City>Capitol City</City>
<Age>33</Age>
<Name />
</PersonObjekt>
</PersonenArray>
</PersonenListe>
<?xml version="1.0"?>
<dictionary>
<item>
<key>
<string>test1</string>
</key>
<value>
<string>test2</string>
</value>
</item>
</dictionary>
after serialization an object of this class:
[XmlType("Person")] // define Type
public class Person
{
[XmlElement("PropertyType")]
public PropertyType PropertyType { get; set; }
[XmlElement("ID")]
public string ID { get; set; }
[XmlElement("Name")]
public string Name { get; set; }
[XmlElement("City")]
public string City { get; set; }
[XmlElement("Age")]
public Dictionary<object, object> Age { get; set; }
}
I have this code:
<PersonenListe>
<PersonenArray>
<PersonObjekt>
<PropertyType>Unknown</PropertyType>
<ID>0</ID>
<FriendlyName>Max Man</FriendlyName>
<City>Capitol City</City>
<Age>33</Age>
<Name>
<item>
<key>
<anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" p8:type="q1:string" xmlns:p8="http://www.w3.org/2001/XMLSchema-instance">test1</anyType>
</key>
<value>
<anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" p8:type="q1:string" xmlns:p8="http://www.w3.org/2001/XMLSchema-instance">test2</anyType>
</value>
</item>
</Name>
</PersonObjekt>
</PersonenArray>
</PersonenListe>
How can I clean up it(I want to have code without this namespaces)? maybe using some attributes?
Update:
when I serialize it separetly I get:
<PersonenListe>
<PersonenArray>
<PersonObjekt>
<PropertyType>Unknown</PropertyType>
<ID>0</ID>
<FriendlyName>Max Man</FriendlyName>
<City>Capitol City</City>
<Age>33</Age>
<Name />
</PersonObjekt>
</PersonenArray>
</PersonenListe>
<?xml version="1.0"?>
<dictionary>
<item>
<key>
<string>test1</string>
</key>
<value>
<string>test2</string>
</value>
</item>
</dictionary>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)