C# 在c中从xml中从父节点读取子节点#

C# 在c中从xml中从父节点读取子节点#,c#,xml,C#,Xml,在parentParameters下,我将childParameter作为“水果”和“交易ID”。我想同时读取“Fruit”和“TransactionID”的值 xml代码: <soap:Parameters> <soap:Parameter> <soap:Name>Fruit</soap:Name> <soap:Value>Apple</soap:Value> </soap

在parentParameters下,我将childParameter作为“水果”和“交易ID”。我想同时读取“Fruit”和“TransactionID”的值

xml代码:

  <soap:Parameters>
    <soap:Parameter>
      <soap:Name>Fruit</soap:Name>
      <soap:Value>Apple</soap:Value>
    </soap:Parameter>
    <soap:Parameter>
      <soap:Name>TransactionID</soap:Name>
      <soap:Value>1111111</soap:Value>
    </soap:Parameter>
  </soap:Parameters>

果
苹果
事务ID
1111111
这对我很有效

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xDoc.NameTable);
nsmgr.AddNamespace("soap", "http://schemas.xmlsoap.org/soap/envelope/");
var parentNodes = xDoc.SelectNodes("//soap:DataReq/soap:Extensions/soap:Extension/soap:Parameters", nsmgr);

首先使用XDocument类解析XML文件,然后使用Linq查询在父节点上迭代使用Linq to XML