我想反序列化以下 XML 文件:<?xml version="1.0" encoding="utf-8"?><function xmlns="urn:google.com" > <file>my.xml</file> <name>My</name> <arguments> <argument type="int" object="a"/> <argument type="char" object="b"/> </arguments> <return_type>int</return_type> <sql>MySql</sql> <content>xyz</content></function>. 所以,我写了以下代码:public class Argument { [XmlAttribute("type")] public string Type { get; set; } [XmlAttribute("object")] public string Object { get; set; }}[XmlRoot("function", Namespace = "urn:google.com")]public class Function{ [XmlElement("file")] public string File { get; set; } [XmlElement("name")] public string Name { get; set; } [XmlElement("sql")] public string Sql { get; set; } [XmlElement("return_type")] public string ReturnType{ get; set; } [XmlElement("arguments")] public List<Argument> Arguments { get; set; } [XmlElement("content")] public string Content { get; set; } public static Function Deserialize(string fullPath) { XmlSerializer deserializer = new XmlSerializer(typeof(Function)); TextReader reader = new StreamReader(fullPath); object obj = deserializer.Deserialize(reader); Function f = (Function)obj; reader.Close(); return f; }}该代码工作,除了Type与Object各属性Argument始终null。这段代码有什么问题?
1 回答
翻阅古今
TA贡献1780条经验 获得超5个赞
改变
[XmlElement("arguments")]
public List<Argument> Arguments { get; set; }
到
[XmlArray("arguments")]
[XmlArrayItem("argument")]
public List<Argument> Arguments { get; set; }
- 1 回答
- 0 关注
- 224 浏览
添加回答
举报
0/150
提交
取消