[英]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.