序列化获取节点信息

本文关键字:信息 节点 获取 序列化 | 更新日期: 2023-09-27 18:20:32

<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")]
}

还需要停用书籍属性,我该怎么做?

序列化获取节点信息

要序列化的类没有达到应有的水平。考虑使用这样的:

[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应该可以工作。否则,请检查结果是否有stringint