简体   繁体   English

XML动态序列化/反序列化

[英]XML Dynamic Serialization / Deserialization

I've got an object whose XML structure is dynamic and can change runtime based on the Application. 我有一个对象,它的XML结构是动态的,可以根据应用程序更改运行时。

What I would like to do is specify the XML Element location for each property's declaration. 我想做的是为每个属性的声明指定XML元素位置。 However, it seems this can not be done in runtime and needs to be statically set. 但是,这似乎无法在运行时完成,需要静态设置。 Is there another method for accomplishing what I would want to do? 是否有另一种方法可以完成我想做的事情?

 public class user
 {
      [System.Xml.Serialization.XmlElement(XMLLocation.PersonUsername)]
      public String name;
 }

Since the data is the same but passed along to different applications I'd recommend using the same internal XML and processing it with XSLT before passing it along. 由于数据是相同的,但是传递给了不同的应用程序,所以我建议使用相同的内部XML,并在传递之前使用XSLT对其进行处理。

Implementing IXmlSerializable is certainly possible, so are other approaches, but you'll find yourself writing complex and unmaintainable code. 当然可以实现IXmlSerializable,其他方法也可以,但您会发现自己编写了复杂且不可维护的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM