[英]Unhandled Exception: System.Xml.XPath.XPathException: Expression must evaluate t o a node-set
[英]xml error:System.Xml.XPath.XPathException: Expression must evaluate to a node-set
我试图在我的xml文件中找到一个节点,但出现错误(请参见标题)?
// instantiate XmlDocument and load XML from file
XmlDocument doc = new XmlDocument();
doc.Load(@"C:\temp\test2.xml");
var node = doc.SelectSingleNode("/Offers/Offer/ID=[text()='1']");
var test = node;
XML
<?xml version="1.0" encoding="utf-8"?>
<Offers>
<Offer>
<Model>AAAA</Model>
<ID>1</ID>
<Name>First offer</Name>
</Offer>
<Offer>
<Model>BBBB</Model>
<ID>2</ID>
<Name>Second offer</Name>
</Offer>
</Offers>
删除ID后的=
:
var node = doc.SelectSingleNode("/Offers/Offer/ID=[text()='1']");
变为:
var node = doc.SelectSingleNode("/Offers/Offer/ID[text()='1']");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.