【发布时间】:2020-05-31 20:48:04
【问题描述】:
我进行了很多搜索以找到确切的等价物,但找不到。这里的问题是 java8-javax.xml.xpath.* 的 translate 方法没有给出预期的输出。
例子-
实际-
XPathExpression xpathitemtype = xpath.compile("//*[@type=\"" + xpathType + "\"]/ancestor::itemtype");
final NodeList itemType = (NodeList) xpathitemtype.evaluate(document, XPathConstants.NODESET);
使用翻译-
XPathExpression xpathitemtype = xpath.compile("//*[translate(@type,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='" + xpathType.toLowerCase() + "']/ancestor::itemtype");
final NodeList itemType = (NodeList) xpathitemtype.evaluate(document, XPathConstants.NODESET);
现在我使用 translate 是因为我喜欢在给定的 xml 文档中获取 itemType 而不管大小写-
例如,如果值是- exportMedia 或 ExportMedia 或 EXportMEdia 在任何情况下都只返回输出。
现在在上面的两个示例中返回相同的输出似乎翻译在我的情况下不起作用
<itemtype code="RemoveCatalogVersionJob">
<attribute qualifier="catalogVersion" type="CatalogVersion">
<persistence type="property"/>
</attribute>
<attribute qualifier="removedItems" type="ExportMEdia">
<persistence type="property"/>
</attribute>
<attribute qualifier="notRemovedItems" type="exportMedia">
<persistence type="property"/>
</attribute>
</itemtype>
如果是 exportMedia 的任何情况,我现在想要项目值
【问题讨论】:
标签: java xpath case-insensitive