XPath用于节点文本?

时间:2016-08-15 18:55:24

标签: java xml xpath xpath-2.0 domxpath

我正在尝试获取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>

1 个答案:

答案 0 :(得分:0)

您的xpath需要更正:

//comparator[contains(VALUE,'item.auxiliaryData.productRef.brandName')]//STRING-VALUE

您使用的是item.auxiliaryData.productRef.ancestorCategoryIds