我无法相信这是多么令人难以置信的复杂......
我有以下 XML ......
<Library xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://mynamespace.com/books">
<Rows>
<Row>
<Author><Name>Stephen King</Name></Author>
</Row>
</Rows>
</Library>
我希望反序列化的 C# 对象读起来像......Library.Books[0].Author
我已经尝试过一百万种不同的 XML 属性标记组合来反序列化,例如...
[XmlRootAttribute("Library", Namespace = "http://mynamespace.com/books", IsNullable = false)]
public class Library
{
[XmlElement("Rows")]
public List<Book> Books { get; set; }
}
[XmlRoot("Row")]
public class Book
{
public Author Author { get; set; }
}
[XmlRoot("Author")]
public class Author
{
public string Name { get; set; }
}
...当我尝试反序列化时,我不断地将“作者”对象设为空。它几乎成功了...我确实在 Books 属性中获得了带有一个 Book 项目的 ArrayList。但是对于我的生活,我无法获得作者。
任何建议/帮助将不胜感激!