-3

我有以下XML:

<Requests xmlResponse="true">
<Request response="yes" responsewait="120000" sequence="1" type="Fulfillment">
<RequestData>
  <PrintControl>FTP</PrintControl>
  <User>81DF</User>
  <Documents>
    <AddressChangeLetter>
      <DocumentInfo>
        <AddressChange AddressChangeId="109346" Branch="418" LastChangeDate="">
          <Name>AAA NOVAK</Name>
          <TaxID>123123121</TaxID>
          <OldAddress1>BOX 216</OldAddress1>
          <OldAddress2>NYANE 68017</OldAddress2>
          <OldAddress3 />
          <OldAddress4 />
          <NewAddress1>P O BOX 216</NewAddress1>
          <NewAddress2>CERESCO NE 68017</NewAddress2>
          <NewAddress3 />
          <NewAddress4 />
          <DateChanged>05/08/2013</DateChanged>
          <AccountInfo AcctNum="231232311" AcctStatusCodes="IX" />
        </AddressChange>
      </DocumentInfo>
    </AddressChangeLetter>
  </Documents>
</RequestData>

我想获取标签“文档”下的名称或值。由于在上面的 XML 中,“Document”标签下的标签是“AddressChangeLetter”,因此,我想获取这个名称。我将如何做。

4

2 回答 2

0

类似于......(它并不完美,但它会让你开始 - 谷歌我用来让它正常工作的功能):

XmlDocument xml = new XmlDocument();
xml.Load(yourPathGoesHere)

XmlNodeList addressNodes = xml.GetElementsByTagName("AddressChange");

foreach (XmlNode oneNode in addressNodes) {
  myVariableToGrabNames = oneNode["Name"].InnerText;
}
于 2013-05-10T10:39:55.953 回答
0

这可以使用Linq to XML轻松完成,例如

var xml = ...;
var xdoc = XDocument.Parse(xml);
foreach (var e in xdoc.Descendants("Documents").Elements())
{
    var name = e.Name; // AddressChangeLetter
}
于 2013-05-10T10:40:46.773 回答