访问嵌套的XML节点

时间:2014-07-24 18:49:17

标签: c# .net xml

我无法导航到某些嵌套的XML节点。我正在使用XpathNavigator并且可以看到已捕获的正确节点,但我无法正确解析它们。任何帮助将不胜感激:

<root>
  <audits>
<supervisorAuditId>311004</supervisorAuditId>
    <supervisorName>Munjkhkiz, John</supervisorName>
    <supervisorCenter>CA</supervisorCenter>
    <supervisorManager>HNubnot, Harry</supervisorManager>
    <followupDate>07/31/2014</followupDate>
    <graded>3</graded>
    <addedOn>07/23/2014</addedOn>
    <addedBy>HNubnot, Harry</addedBy>
    <responses>
      <mqField>BM1</mqField>
      <mqFieldTitle>Balanced Coaching</mqFieldTitle>
      <comments>another test</comments>
      <actions>another test 1</actions>
    </responses>
    <responses>
      <mqField>BM5</mqField>
      <mqFieldTitle>Productivity</mqFieldTitle>
      <comments>another test 4</comments>
      <actions>another test 5</actions>
    </responses>
    <responses>
      <mqField>BM3</mqField>
      <mqFieldTitle>Conduct</mqFieldTitle>
      <comments>another test 2</comments>
          <actions>another test 3</actions>
    </responses>
  </audits>
</root>

代码:

foreach (System.Xml.XPath.XPathNavigator item2 in iterator)
{
    System.Xml.XPath.XPathNavigator _element2 = item2.SelectSingleNode("audits/responses");

    _element2 = item2.SelectSingleNode("responses[@mqField='BM1']");
    comments1 = _element2.Value;

    _element2 = item2.SelectSingleNode("responses/actions");
    actions1 = _element2.Value;
}

0 个答案:

没有答案