我有以下xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="root">
<xs:complexType>
<xs:sequence>
<xs:any processContents="skip" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
以及以下绑定:
<jxb:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1">
<jxb:bindings schemaLocation="format.xsd">
<jxb:bindings node="//xs:any">
<jxb:property>
<jxb:baseType>
<jxb:javaType name="org.w3c.dom.Element"
parseMethod="leif.ElementFormatter.parseElement"
printMethod="leif.ElementFormatter.printString" />
</jxb:baseType>
</jxb:property>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
但是当我运行xjc ...
时
xjc -p leif -b bindings.xml format.xsd
我收到以下错误:
parsing a schema...
[ERROR] compiler was unable to honor this javaType customization. It is attached to a wrong place, or its inconsistent with other bindings.
line 9 of file:/C:/Users/leif/workspace/doughan/src/main/resources/bindings.xml
[ERROR] (the above customization is attached to the following location in the schema)
line 7 of file:/C:/Users/leif/workspace/doughan/src/main/resources/format.xsd
Failed to parse a schema.
仅在为javaType
定义xs:any
时才会发生,当我将其更改为xs:element
时,它才有效。但我真的需要它xs:any
。
我的目标是获得这样的课程:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Root {
@XmlJavaTypeAdapter(Adapter1.class)
@XmlAnyElement
String any;
}