繁体   English   中英

xml错误:System.Xml.XPath.XPathException:表达式必须计算为节点集

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM