XML Serialization, in this case IXmlSerializable or Attributes

I've done XML serialization before, but I used attributes, I'm not sure if it's doable for my next assignment, here is a short list of XML manipulation requirements.

  • Generic XMl manipulation tied to a tree structure, no schema.
  • Load / Save XML.
  • Load / save attributes as well as values ​​(I believe this is the term "Elemental Text?"), And remember the name Node.
  • Comments can be safely ignored as well as markup of document information (i.e. UTF-8 tags and schemas)

Any suggestions on the best way to handle this?

+1


a source to share


3 answers


I probably wouldn't bother with the object model and IXmlSerializable

- it looks like you can just talk about terms XmlElement

/ XmlDocument

- for example, pass data as an xml block. Since you have no schema, it would be pointless to destroy it; you can also do it with XML-DOM.



When you say treeview is winforms, asp.net, wpf? I believe treeview in asp.net can take the xml source, but for winforms you will have to iterate the nodes yourself.

0


a source


Not sure what exactly you mean with "before, but I used attributes", but I would recommend the XmlSerializer:



  • With "simple" classes, it usually works out of the box.
  • Collections may need some more work, but it depends on your requirements and the structure of the objects.
  • There are other assemblies in XML serializers, such as XAML or WCF DataContractSerializer. They all have pros and cons. But if you want to fine-tune your XML format, XMLSerializer is the most flexible.
  • You can approach your format step by step: if the default looks good, do so. If not, you only need to add some attributes in most cases.
  • If you want complete control, you can still implement IXmlSerialize to fine tune your format.
  • Everything applies to every class: use the defaults where necessary, add some attributes where necessary, and add IXmlSerializable as needed.
0


a source


I would suggest that you use the simple XML serialization supported by the .NET framework.

Go to this MSDN documentation

Object serialization

How to deserialize an object

-1


a source







All Articles