私は、.NET C#で複数の単一のxml要素を含むxmlを逆シリアル化しようとしています。
<Root>
<Status>OK</Status>
<Person>
<Name>Element 1</Name>
</Person>
<Person>
<Name>Element 2</Name>
</Person>
</Root>
Personノードは、 <Persons></Persons>
だから、私は使用することはできません [XmlArray]
属性。
XDocumentでXPathを使用しなくても、だれでもそれを行うことを知っていますか。
ありがとう
回答:
回答№1は1.NET 3.5以上を使用している場合は、Linq-to-XMLを使用してください。
string xml = "<root>...</root>";
XDocument doc = XDocument.Parse(xml); // Use .Load() if loading from a file
String status = doc.Root.Element("status").Value;
IEnumerable<string> personNames = doc.Root.Descendants("person").Select(x => x.Element("name").Value);