【问题标题】:Search wildcard with xpath in docx4j在 docx4j 中使用 xpath 搜索通配符
【发布时间】:2019-03-12 01:14:01
【问题描述】:

您好,可以在 docx4j 中使用 xpath 搜索通配符吗?

考虑这个例子:

<w:r>
    <w:rPr>
       <w:lang w:bidi="fa-IR" />
    </w:rPr>
    <w:t>priority: {priority}</w:t>
</w:r>
<w:r>
    <w:rPr>
       <w:lang w:bidi="fa-IR" />
    </w:rPr>
    <w:t>{effectiveLocations}</w:t>
</w:r>

我需要找到所有文本包含 *{*}* 的运行,这意味着我需要在上面的示例中获得两个运行。

但是docx4j使用的是XPath 1.0,所以不支持matches查询,还有其他方法吗?

【问题讨论】:

    标签: java xpath saxon docx4j xpath-2.0


    【解决方案1】:

    https://docx4java.org/docx4j/docx4j-nightly-20181009.jar 包含https://github.com/plutext/docx4j/commit/cab8adcb768c18103e7a9b48ac39dc8fcde5ff0c

    所以如果你的类路径中有https://search.maven.org/artifact/net.sf.saxon/Saxon-HE/9.9.0-1/jar

    你可以这样做:

    XPathFactoryUtil.setxPathFactory(
            new net.sf.saxon.xpath.XPathFactoryImpl());
    

    【讨论】:

      猜你喜欢
      • 2017-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多