我正在尝试制作一个通用的 XmlParsing 方法。以 XML 为例:
<body>
<section>
<subsection1>
...
</subsection1>
<subsection2>
...
</subsection2>
</section>
<section>
<subsection1>
...
</subsection1>
<subsection2>
...
</subsection2>
</section>
</body>
我试图在不知道它们有多深或它们的父节点名称的情况下抓取所有“部分”节点。
到目前为止我有(我的 XML 是字符串格式)
XmlDocument xml = new XmlDocument();
xml.LoadXml(XMLtoRead);
XmlNodeList nodes = xml.DocumentElement.SelectNodes("//section");
但是节点数始终为 0。我的印象是“//”前缀递归地在文档中搜索命名节点。
我真正的 XML 是一个 SOAP 回复:
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Response xmlns="http://tempuri.org/">