更新时间:2022-10-15 12:11:59
在 XmlMagic
你以后叫的IXmlSerializable
接口:的http://msdn.microsoft.com/en-us/library/system.xml.serialization.ixmlserializable.aspx
它为您提供了2种方法的ReadXml
和中WriteXML
,在那里你必须实现读你的对象,并写它背部。然后,可以使用标准的.NET 的XmlSerializer
序列化/反序列化对象。
让我知道如果你需要更多的帮助。
i need help, i have some data coming in xml, i want to make an object out of, do something with it, serialize it back and send it away... but it must be some sort of custom serialization.
xml like:
<Animals Ver="12" class="1" something="2">
<Dog Ver="12" class="2" something="17">
<Name> a </Name>
<Sound> oof </Sound>
<SomeOtherProp>12</SomeOtherProp>
</Dog>
<Cat Ver="12" class="3" something="4">
<Name> b </Name>
<Sound> meow </Sound>
</Cat>
</Animals>
needs to be presented as:
abstract class Animal :XmlMagic
{
public string Name{get;set;}
public string Sound{get;set;}
public void SomeMagicalXMLSerializationMethod()
{}
public void SomeMagicalXMLDeSerializationMethod()
{}
}
class Dog: Animal, XmlMagic
{
public int SomeOtherProp{get;set;}
public void SomeMagicalXMLSerializationMethod()
{}
public void SomeMagicalXMLDeSerializationMethod()
{}
}
The XmlMagic
you are after is called IXmlSerializable
interface: http://msdn.microsoft.com/en-us/library/system.xml.serialization.ixmlserializable.aspx
It provides you with 2 methods ReadXml
and WriteXml
, where you have to implement reading your object and writing it back. Then you use the standard .Net XmlSerializer
to serialize/deserialize your objects.
Let me know if you need more help.