xml - maven 和 xml 解析的 Hibernate 依赖问题

标签 xml hibernate dom maven-2 xpath

我正在为我们的开发团队编写 GWT-Hibernate 内部 Web 应用程序。

之前,我编写了工具来解析 XML 文件,这些文件表示在现场收集的客户配置以供分析。现在,我正在尝试为支持组添加一个 UI 前端。 XML 解析代码使用 xpath 和 org.w3c.dom 类来使用配置文件,在将 UI 和解析代码合并到同一个项目后,我遇到了依赖性问题。 Hibernate 3.5.1 依赖于使用旧版本 xml-apis 的 dom4j。 xml-apis jar 有旧版本的 org.w3c.dom 类,太旧以至于我在 XML 解析中使用的方法之一不可用。

org.w3c.dom.Node.getTextContext 方法在旧的 xml-apis 类中不可用。


Node node = (Node)xpath.evaluate("//probe/configfile[@group=\"daemon.ini\"]/content", data, XPathConstants.NODE);
        if(node != null) {
            String content = node.getTextContent();
                // Do more work...

maven dependency:tree 显示问题,hibernate,dom4j,xml-apis 1.0.b2。

[INFO] +- org.hibernate:hibernate-core:jar:3.5.1-Final:compile
[INFO] |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile

关于解决此问题的最佳方法的建议?

  1. Maven 依赖配置?我是 Maven 的新手,所以要明确。
  2. 使用不同的 API 解析 XML?

提前致谢。

最佳答案

我不知道什么版本适合你,但可以通过在 <dependencyManagement> 中声明来控制传递依赖的版本元素:

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>xml-apis</groupId>
        <artifactId>xml-apis</artifactId>
        <version>1.3.04</version>
      </dependency>
    </dependencies>
  </dependencyManagement>

这是你会得到的:

[INFO] +- org.hibernate:hibernate-entitymanager:jar:3.5.4-Final:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:3.5.4-Final:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.6:compile
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.3.04:compile (version managed from 1.0.b2)

但正如我所写,我不知道哪个版本适合您的需求以及它们是否向后兼容。

关于xml - maven 和 xml 解析的 Hibernate 依赖问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3522648/

相关文章:

android - 如何通过显式创建 AndroidManifest.xml 来创建 android 应用程序?

java - JPA/hibernate : code based validation of jpa queries

java - Spring JPA 多对多 : remove entity, 删除连接表中的条目,但不删除另一侧

javascript - 为什么jQuery或诸如getElementById之类的DOM方法找不到元素?

javascript - 浏览器密码自动填充的 DOM 事件?

c# - 如何在 C# 中将字符串解码为 XML 字符串

c# - 使用 EWS 阅读电子邮件时处理非法 XML 值

java - 如何使用 Java 在根元素中获取多个命名空间定义?

stored-procedures - 如何在 Hibernate 中创建临时表?

javascript - HTML/JS 良好实践 : Is it good to add too many ids?