节点文本的 XPath?
XPath for text of node?
我正在尝试获取 STRING-VALUE 的内容,其中比较器的 VALUE = item.auxiliaryData.productRef.brandName
我尝试使用下面的代码,
XPathExpression expr = xpath.compile
("//comparator[contains(VALUE,'item.auxiliaryData.productRef.ancestorCategoryIds')]//STRING-VALUE");
productRefs = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
这就是我要解析的内容
<comparator NAME="equals">
<VALUE>item.auxiliaryData.productRef.brandName</VALUE>
<CONSTANT>
<DATA-TYPE>java.lang.STRING</DATA-TYPE>
<STRING-VALUE>Ariat</STRING-VALUE>
</CONSTANT>
</comparator>
<comparator NAME="equals">
<VALUE>item.auxiliaryData.productRef.ID</VALUE>
<CONSTANT>
<DATA-TYPE>java.util.Collection</DATA-TYPE>
<STRING-VALUE>84332</STRING-VALUE>
<STRING-VALUE>79904</STRING-VALUE>
<STRING-VALUE>82203</STRING-VALUE>
</CONSTANT>
</comparator>
您的 xpath 需要更正:
//comparator[contains(VALUE,'item.auxiliaryData.productRef.brandName')]//STRING-VALUE
您正在使用 item.auxiliaryData.productRef.ancestorCategoryIds
这个 XPath,
string(//comparator[VALUE='item.auxiliaryData.productRef.brandName']//STRING-VALUE)
将return"Ariat"
直接按照要求。
我正在尝试获取 STRING-VALUE 的内容,其中比较器的 VALUE = item.auxiliaryData.productRef.brandName
我尝试使用下面的代码,
XPathExpression expr = xpath.compile
("//comparator[contains(VALUE,'item.auxiliaryData.productRef.ancestorCategoryIds')]//STRING-VALUE");
productRefs = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
这就是我要解析的内容
<comparator NAME="equals">
<VALUE>item.auxiliaryData.productRef.brandName</VALUE>
<CONSTANT>
<DATA-TYPE>java.lang.STRING</DATA-TYPE>
<STRING-VALUE>Ariat</STRING-VALUE>
</CONSTANT>
</comparator>
<comparator NAME="equals">
<VALUE>item.auxiliaryData.productRef.ID</VALUE>
<CONSTANT>
<DATA-TYPE>java.util.Collection</DATA-TYPE>
<STRING-VALUE>84332</STRING-VALUE>
<STRING-VALUE>79904</STRING-VALUE>
<STRING-VALUE>82203</STRING-VALUE>
</CONSTANT>
</comparator>
您的 xpath 需要更正:
//comparator[contains(VALUE,'item.auxiliaryData.productRef.brandName')]//STRING-VALUE
您正在使用 item.auxiliaryData.productRef.ancestorCategoryIds
这个 XPath,
string(//comparator[VALUE='item.auxiliaryData.productRef.brandName']//STRING-VALUE)
将return"Ariat"
直接按照要求。