我愿意接受所有建议,但如果可能,不要循环。我想从这个XML到一个变量的NUM发现的属性,但它回来NULL,我想不通为什么:C#和XPath - 获取属性?
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlStringGoesHere);
int intNumFound = Convert.ToInt32(xmlDoc.SelectSingleNode("/orcid-message/orcid-search-results/@num-found").Value);
我想使用SelectSingleNode,因为它是一行代码。有人建议下面这样做,但这两者都不起作用。此外,有没有办法做到这一点,没有所有的“本地名称”废话臃肿的代码?
object intNumFound = xmlDoc.SelectSingleNode("/*[local-name() = 'orcid-message']/*[local-name() = 'orcid-search-results']");
object intNumFound = xmlDoc.SelectSingleNode("/*[local-name() = 'orcid-message']/*[local-name() = 'orcid-search-results']/@num-found]");