IXmlSerializable, reading xml tree with many nested elements
问题 Could you guys give me an example how to read and write from/to xml like this: <Foolist> <Foo name="A"> <Child name="Child 1"/> <Child name="Child 2"/> </Foo> <Foo name = "B"/> <Foo name = "C"> <Child name="Child 1"> <Grandchild name ="Little 1"/> </Child> </Foo> <Foolist> 回答1: Does the element name really change per level? If not, you can use a very simple class model and XmlSerializer . Implementing IXmlSerializable is... tricky; and error-prone. Avoid it unless you absolutely have to use