1

我试图在我的 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>
4

1 回答 1

2

删除=后面的 ID:

 var  node = doc.SelectSingleNode("/Offers/Offer/ID=[text()='1']");

变成:

 var  node = doc.SelectSingleNode("/Offers/Offer/ID[text()='1']");
于 2013-06-28T02:12:34.700 回答