我有以下 XML
<?xml version="1.0" ?>
<SERVICES.OUTPUTResponse>
<Results>
<Result>
<Dataset name="OutputData">
<Row>
<country>USA</country>
<pubyear>9986</pubyear>
<numart>123</numart>
<numcites>456</numcites>
</Row>
<Row>
<country>USA</country>
<pubyear>97</pubyear>
<numart>895</numart>
<numcites>231</numcites>
</Row>
</Dataset>
<Dataset name="Result 2">
<Row>
<Result_2>
true
</Result_2>
</Row>
</Dataset>
</Result>
</Results>
<_Probe></_Probe>
</SERVICES.OUTPUTResponse>
我尝试使用 XmlSerializer 反序列化,但它返回 null。
我使用的 Property 类是
公共类 XMLDetails {
public string country { get; set; } public string pubyear { get; set; } public string numart { get; set; } public string numcites { get; set; } }
反序列化代码是
XmlRootAttribute xRoot = new XmlRootAttribute();
xRoot.ElementName = "SERVICES.OUTPUTResponse";
xRoot.IsNullable = true;
var serializer = new XmlSerializer(typeof(XMLDetails), xRoot);
var reader = new StringReader(remoteXml);
var objpublication = (XMLDetails)(serializer.Deserialize(reader));
请帮我重新爱上它