<SHEET>
<books title ='title'>
<book label='1' page='1' intro='1'/>
<book label='2' page='2' intro='2'/>
<book label='3' page='3' intro='3'/>
</books>
<books title ='title'>
<book label='1' page='1' intro='1'/>
<book label='2' page='2' intro='2'/>
<book label='3' page='3' intro='3'/>
</books>
</SHEET>
所以我有这个代码,我用它来获取书籍项目中的属性。 我使用这段代码:
[XmlRoot("SHEET")]
public class BookRoot
{
private readonly List<Book> books = new List<Book>();
[XmlArray("books"), XmlArrayItem("book")]
public List<Book> Books { get { return books; } }
}
public class Book {
[XmlAttribute("label")]
}
我还需要退出书籍属性,我该怎么做?
答案 0 :(得分:0)
您要序列化的课程不尽如人意。考虑使用这样的:
[XmlRoot("SHEET")]
public class Sheet
{
[XmlElementAttribute("books")]
public sheetBooks[] books;
public Sheet()
{}
}
public class sheetBooks
{
[XmlAttribute("title")]
public string title;
[XmlElementAttribute("book")]
public sheetBook book;
public sheetBooks()
{}
}
public class sheetBook
{
[XmlAttribute("label")]
public char label;
[XmlAttribute("page")]
public char page;
[XmlAttribute("intro")]
public char intro;
public sheetBook()
{}
}
标签,页面,介绍 - 它们总是低于10?在这种情况下char
应该有效。否则,请检查string
或int