[英]C# Classes for XML Serialize
我正在嘗試編寫C#類,在序列化時將形成此XML結構:
<?xml version="1.0" encoding="utf-8"?>
<Main>
<Current>A34-3</Current>
<Future>
<Role>10</Role>
<Route>T14-3</Route>
<Route>T14-4</Route>
</Future>
</Main>
這是我到目前為止的內容,但是輸出(下面)與上面顯示的完全不一樣。
public class Main
{
public string Current {get; set;}
public Future Future {get;set;}
}
public class Future
{
public string Role {get;set;};
public string[] Route {get;set;}
}
這是我進行序列化時的輸出:
<?xml version="1.0" encoding="utf-16"?>
<Main xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Current>A34-3</Current>
<Future>
<Role>10</Role>
<Route>
<string>T14-3</string>
<string>T14-4</string>
</Route>
</Future>
</Main>
另外,我在Visual Studio中嘗試了xsd.exe程序,但是生成的類並不是我想要的。 有人可以幫助我首先列出該結構嗎?
結構很好。 只需使用[XmlElement]
屬性裝飾數組即可告訴序列化程序如何運行。
[XmlElement]
public string[] Route { get; set; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.