使用包含特定innertext的子节点选择Single node。的XMLDocument

时间:2013-12-23 12:33:17

标签: c# .net xml xmldocument

您好我正在处理XmlDocument检索

我的部分文件是

 <Product ID="102166"> 
        <Name>Name1</Name> 
         <Mrp>220.0000</Mrp> 
         <Price>210.2800</Price> 
          <Cost>177.8700</Cost> 
         <Barcode>102166,10216610,8901786409990,9910216600011,10216620,9910216600202
    </Barcode>
 </Product> 

我想从其商品代码内部文字包含给定字符串

的文档中选择单个产品节点

例如,如果我将8901786409990作为输入输出应该是其父级,即ID为102166的产品

我试过以下但没有成功

string ItemCode="8901786409990 ";
 XmlNode node = doc.SelectSingleNode("/*/b:Product[contains(b:Barcode,'" + Itemcode1 + "')");

抛出异常'/*/b:Product[contains(b:,'8901786409990')'有一个无效的令牌。

任何帮助?

1 个答案:

答案 0 :(得分:3)

你错过了一个近距离的支架:

string ItemCode="8901786409990 ";
 XmlNode node = doc.SelectSingleNode("/*/b:Product[contains(b:Barcode,'" + Itemcode1 + "')]");

请参阅此处的额外括号:

'/ * / B:产品[含有(B:' 8901786409990')的