0
我正在用xmlserialize類創建一個xml文件,我得到的輸出幾乎是我所需要的。 這是我得到自定義XmlSerialize輸出
<?xml version="1.0" encoding="UTF-8"?>
<pdf file-name="C:\Users\d.sassoli\Desktop\media\mergiato.pdf" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<document>
<document start-page="1">
<SheetChange>
<SheetChange sheet-type="A4" page-number="1"/>
<SheetChange sheet-type="A3" page-number="2"/>
</SheetChange>
</document>
</pdf>
這就是我想要
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<pdf file-name="C:\Users\d.sassoli\Desktop\media\mergiato.pdf" >
<document start-page="1">
<SheetChange sheet-type="A4" page-number="1"/>
<SheetChange sheet-type="A3" page-number="2"/>
</pdf>
這些都是我的課,我確定我的XML
[XmlRootAttribute("pdf", IsNullable = false)]
public class Pdf
{
private Pdf() { }
public static Pdf Builder()
{
Pdf pdf = new Pdf();
return pdf;
}
[XmlAttribute("file-name")]
public List<string> FileName { get; set; }
public List<document> document;
}
public class document
{
private document() { }
public static document Builder()
{
document doc = new document();
return doc;
}
[XmlAttribute("last-page")] public string LastPage;
[XmlAttribute("start-page")] public string StartPage;
public List<SheetChange> SheetChange;
}
public class SheetChange
{
private SheetChange() { }
public static SheetChange Builder()
{
SheetChange sheetChange = new SheetChange();
return sheetChange;
}
[XmlAttribute("page-number")]
public string PageNumber { get; set; }
[XmlAttribute("sheet-type")]
public string SheetType { get; set; }
}
我的結構嘗試擺弄xmlattribute但沒有達到我想要的。