我正在尝试从 XML 文件中获取一个节点并且玩得很开心。XML:
<?xml version="1.0" encoding="UTF-8"?>
<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>26.0</apiVersion>
<label>aaaWsPage2</label>
<description></description>
<rffolder>Robert Test</rffolder>
</ApexPage>
我尝试了以下代码:
var doc = new XmlDocument();
doc.Load(@"c:\test.xml");
var mgr = new XmlNamespaceManager(doc.NameTable);
mgr.AddNamespace("ns1", @"http://soap.sforce.com/2006/04/metadata");
XmlElement root = doc.DocumentElement;
string query = @"/ns1:ApexClass/ns1:rffolder";
var xmlNode = root.SelectSingleNode(query);
if (xmlNode != null)
Console.WriteLine(xmlNode.InnerXml);
xmlNode
始终为空,否则我在.SelectSingleNode
. 我在这里想念什么?