Xml XPath-测试属性值和文本值

Xml XPath-测试属性值和文本值,xml,parsing,xpath,xml-parsing,Xml,Parsing,Xpath,Xml Parsing,我试图编写一个Xpath条件,如果元素的属性和值正确,则返回该元素,否则返回null 这是我的xml <record> <field name="uid">ABC70019469</field> <field name="effectiveDate">10 May 2014 00:00:00 BST</field> <field name="expiryDate">09 May 2015 23:59:59 BST

我试图编写一个Xpath条件,如果元素的属性和值正确,则返回该元素,否则返回null

这是我的xml

<record>
  <field name="uid">ABC70019469</field>
  <field name="effectiveDate">10 May 2014 00:00:00 BST</field>
  <field name="expiryDate">09 May 2015 23:59:59 BST</field>
  <field name="price">48.49</field>
  <field name="cancelled">{cancelled}</field>
  <field name="addonSection.effectiveStartTime">09 May 2014 09:04:29 BST</field>
  <field name="addonSection.effectiveEndTime">31 December 9999 23:59:59 GMT</field>
  <field name="addonSection.brand">BIT</field>
  <field name="addonSection.product">ProPlus</field>
<record>
欢迎发表意见


谢谢

您不需要在条件之间使用
/
。使用
加入您的支票:

//field[@name='addonSection.product' and text()='ProPlus']
演示(使用):

$xmllint input.xml--xpath//field[@name='addonSection.product'和text()='ProPlus']
本体

谢谢,我刚刚意识到我的实际代码中也少了一个大写字母。脸掌。非常感谢
//field[@name='addonSection.product' and text()='ProPlus']
$ xmllint input.xml --xpath "//field[@name='addonSection.product' and text()='ProPlus']"
<field name="addonSection.product">ProPlus</field>