问题标签 [javax.xml]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
58 浏览

java - XPath - Java XPath 结果意外

我注意到了一些奇怪的事情。这是我的 XML

这是我使用的 XPath

/Items/Item[((Amount * Quantity) != TotalAmount)]/名称

此 XPath 必须打印 TotalAmount!= Product( Amount, Quantity ) 的项目的名称。

我得到值 A。但我不明白为什么会这样因为0.0012 * 17 = 0.0204

如果我删除项目'A',那么我不会得到结果。

新版本的 XPath 也是如此

对于 /Items/Item[((Amount * Quantity) != TotalAmount)] 中的 $x,返回 $x/Name

我在 Java 中使用 Saxon 9。

有人可以解释为什么会这样。

0 投票
1 回答
167 浏览

xml - 是否可以从 XPathExpression 获取 XPATH 查询字符串?

一个 XPath 查询被编译成一个 XPathExpression,然后可以在文档上进行评估。假设如果我只持有所有已编译的表达式,是否有可能知道它们各自的 xpath 查询是什么?

0 投票
1 回答
11964 浏览

java - Java 9 中的 javax.xml.bind 去了哪里?

我尝试将我的项目从 JDK 1.8 迁移到 Java 9,但它无法编译。我的项目使用了很多javax.xml.bind.annotation类,似乎它们丢失了。它们是移到某个地方还是被弃用了?

0 投票
1 回答
1257 浏览

xml - While validating against XSD, find the exact missing element in the XML using any of DOM, StAX, SAX parsers

I have a XML file and its corresponding XSD file. While validating using StAX parser, I've attached an error handler. Basically, I encounter two types of errors in a well-formed XML file.

1) Incorrect type of data inside an element, for e.g string inside an element that is supposed to have an integer.

2) Missing element: An element that must be present according to XSD is not present in the XML.

Using a StAX parser and custom error handler, I'm able to rectify the first type of error. But for the second type, a CHARACTER event is triggered and the value of the TEXT is the value of immediate next element. I don't know how to figure out the missing element. Also, why the CHARACTER event is triggered and the missing element is completely ignored?

As the StAX parser is forward only, is there a way to rectify both of the errors using other parsers?

Below is the snippet of the well-formed XML file:

Here the HumanSubjectsIndicator element is commented to provoke the second scenario. In this case a CHARACTER event is triggered in the 'MyErrorHandler'. The value 'Y:Yes' is obtained reader.getTextCharacters(). This value corresponds to the HumanSubjectsIndicator1 element (found this using the getLocation() method).

Is there a way to get exactly the Local Name of the missing element. If not using StAX, then using other parsers?

Thanks.

0 投票
0 回答
307 浏览

xml - 有没有办法在验证 XML 文件时从 SAXParseException 消息中获取元素名称?

SAXParseException 消息是:

一种方法:'PHSHumanSubjectsAndClinicalTrialsInfo-V1.0:HumanSubjectsIndicator' <- getElementNameFromExceptionMessage()

除了模式匹配,有没有办法从异常消息中获取缺少的元素名称?该消息可能在某处内部形成。因此问题。

0 投票
1 回答
657 浏览

java - 如何在 XSLT 上提供实用程序同时保持安全性

我希望能够提供可在 XSL 样式表中使用的转义实用程序。例如:

但是,就 Java 而言,我的理解是在您的 TransformerFactory 上缺少以下设置可能是不安全的:

所以我这样做了,但可以理解的是,这会阻止您使用“外部函数调用”并出现以下运行时错误:

删除上述 FEATURE_SECURE_PROCESSING 标志将解决该问题。

我怎样才能包含一个可以在 XSLT 中调用的实用程序函数,而不会因为能够公开任意 Java 类而导致安全性损失?

0 投票
0 回答
1770 浏览

java - Eclipse 为 DocumentBuilderFactory.setFeature 提供 java.lang.AbstractMethodError

我正在尝试为 maven 项目运行 junit,但由于收到错误消息而无法继续

java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V

似乎eclipse无法找到上述方法的实现。我的 Eclipse 配置了jdk 1.8.0_144. 但是,如果我使用命令 mvn clean install 从命令行编译项目,它会成功。我只在 Eclipse 中运行它时出现此错误。

0 投票
1 回答
132 浏览

java - 在 Java 中传递多个 xpath 时在 NodeList 中查找节点号

我正在使用 javax.xml.xpath.XPath 包来查找 XML 中存在的节点。代码查找值并返回 NodeList

我的示例 XML 是:

我在 NodeList 中得到 2 个节点,因为 XML 的第二个节点中不存在“类别”。

那么有没有办法识别我从 NodeList 获得的节点是我在 xPath.compile 中传递的 xpath 的结果?因为在这里无法识别值 'category3' 来自节点 2 或 3。

或者无论如何要在 XML 中获取节点号,我从中得到结果。在这个例子中,我应该得到节点 1 和 3,因为我得到的类别来自 XML 的第一个和第三个节点。

另一种方法是传递单个 xpath 而不是多个 xpath。但我不想使用这种方法,因为它很耗时,而且我必须处理很多这样的 XML。

0 投票
1 回答
168 浏览

java - jaxb XML,当 XML 的整数值大于 Java Long 的最大值时不抛出异常

假设我正在尝试使用整数字段 (xs:integer) 解组 XML 文件:13131546456131653154156415616

该值大于 Java Long 的最大值。

当 Jaxb 试图解组它时,我希望得到并捕获一个异常。

反而没有例外,我pojo的object.Value设置为null。

有没有办法检测这种情况何时发生并记录下来?

我试过使用 vec,但什么也没找到(空列表):

0 投票
0 回答
99 浏览

java - 无法反序列化为具体的 Java 类型

我正在构建一个健身追踪器应用程序,它允许用户跟踪他们的锻炼。锻炼由一系列动作组成。抽象的运动类由几个运动子类型扩展。

抽象类:

扩展:

并通过以下方式扩展:

还有两个类似的课程。

允许 PUT 锻炼或 WorkoutResultDTO 的资源方法如下:

WorkoutResultDTO 是我认为导致问题的对象,因为它具有抽象运动对象的 ArrayList。

当我使用邮递员对我的端点执行 PUT 时,返回以下错误:

我被引导相信添加以下行:

将解决此问题,因为该注释将提供有关如何将抽象类反序列化为一种具体类型的足够信息,但情况似乎并非如此。我是否缺少一些其他配置或一些需要执行此操作的自定义类?这两天我一直在尝试解决这个问题,这在谷歌上搜索了很多,但无济于事。欢迎任何意见。谢谢!

编辑:图像中附加的 PUT 请求的详细信息。

PUT 请求的详细信息