我的任务是提取给定复杂类型中每个可选属性的(名称,默认值)对。 我有下面的代码:当使用XSAttributeUse.getValueConstraintValue()时,Apache Xerces抛出java.lang.NoSuchMethodError
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 [email protected]).
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类。 – rmlan
我正在使用Java 8.我如何使它从Maven加载Xerces类? –