【发布时间】:2017-03-16 11:33:42
【问题描述】:
我的任务是提取给定复杂类型中每个可选属性的(名称,默认值)对。 我有以下代码:
XSObjectList attrList = typeDefinition.getAttributeUses();
for (int i = 0; i < attrList.getLength(); i++) {
XSAttributeUse attributeUse = (XSAttributeUse) attrList.item(i);
if (!attributeUse.getRequired()) {
String name = attributeUse.getValueConstraintValue().getNormalizedValue();
String value = /* extracting the default value */;
}
}
这会产生错误:
Exception in thread "main" java.lang.NoSuchMethodError: org/apache/xerces/xs/XSAttributeUse.getValueConstraintValue()Lorg/apache/xerces/xs/XSValue; (loaded from path\to\sdk\jre\lib\xml.jar by <Bootstrap Loader>) called from class my.package.xsd.XSDParser (loaded from file:/path/to/the/project/SwidSigner/target/classes/ by sun.misc.Launcher$AppClassLoader@29b444c2).
at my.package.xsd.XSDParser.getTypeAttributes(XSDParser.java:54)
at my.package.xsd.XSDParser.getAttributes(XSDParser.java:37)
at my.package.Main.main(Main.java:29)
更重要的是,当我将其更改为:
XSObjectList attrList = typeDefinition.getAttributeUses();
for (int i = 0; i < attrList.getLength(); i++) {
XSAttributeUse attributeUse = (XSAttributeUse) attrList.item(i);
XSAttributeDeclaration attributeDecl = attributeUse.getAttrDeclaration();
if (!attributeUse.getRequired()) {
String name = attributeDecl.getValueConstraintValue().getNormalizedValue();
String value = /* extracting the default value */;
}
}
错误仍然发生,但它抱怨 XSAttributeDeclaration 类。使用其他方法没有报错,如
XSComplexTypeDefinition.getAttributeUses()
我正在使用 Maven 导入 Xerces:
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
【问题讨论】:
-
您使用的是什么版本的 Java?看起来它试图从 JRE 的 lib 目录中加载 Xerces 类。
-
我使用的是 Java 8。如何让它从 Maven 加载 Xerces 类?
标签: java xml xsd xerces nosuchmethoderror