0
我有一個XML文檔:C#XPathSelectElements返回null?
<xsd:form-definition xmlns:xsd="http://...m.xsd"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="....xsd" ...>
<xsd:page>
<xsd:formant source-name="label" id="guid1" />
<xsd:formant source-name="label id="guid2" />
<xsd:formant source-name="label" id="guid3">
<xsd:value>2013-04-24</xsd:value>
</xsd:formant>
</xsd:page>
</xsd:form-definition>
和C#代碼,我想通過特定的元素進行迭代,並得到id
屬性和value
(如果存在的話) - 讓說labels
。
要做到這一點,我嘗試代碼
XDocument xml = (document load);
XmlNamespaceManager ns = new XmlNamespaceManager(new NameTable());
ns.AddNamespace("f", "http://m.xsd");
foreach (XElement e in xml.XPathSelectElements("//f:formant[@source-name = 'label']", ns))
{
....
}
但foreach
循環不返回任何元素。爲什麼?