i have problems with the generation of jaxb classes. Especially with namespaces of imported elements. I have the following two schema files:
extension.xsd
<?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="http://www.example.org/extension" elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns="http://www.example.org/extension" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:extern="http://www.example.org/extern"> <xs:import namespace="http://www.example.org/extern" schemaLocation="extern.xsd" /> <xs:element name="Element1"> <xs:complexType> <xs:sequence> <xs:element name="ElementB" type="extern:ElementB" maxOccurs="unbounded" /> </xs:sequence> </xs:complexType> </xs:element> ... </xs:schema> extern.xsd
<?xml version="1.0" encoding="UTF-8"?> <xs:schema targetNamespace="http://www.example.org/extern" elementFormDefault="qualified" attributeFormDefault="unqualified" xmlns="http://www.example.org/extern" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:complexType name="ElementA"> <xs:sequence> ... </xs:sequence> <xs:attribute name="name"/> </xs:complexType> <xs:complexType name="ElementB"> <xs:sequence> ... </xs:sequence> <xs:attribute name="name"/> </xs:complexType> <xs:complexType name="ElementC"> <xs:sequence> ... </xs:sequence> <xs:attribute name="name"/> </xs:complexType> ... </xs:schema> example xml file
<Doc targetNamespace="http://www.example.org/extern xmlns="http://www.example.org/extern"> ... <extension:Element1 xmlns:extension="http://www.example.org/extension"> <ElementB name="someName"> .... </ElementB> </test:Element1 > ... </Doc> extern.xsd contains a lot of different complex types. In extension.xsd I want to reuse one of this complex types (ElementB). extern.xsd is fixed and cant't be modified. The targetNamespace of the xml is fixed too.
2 Questions:
1.) The generated Element1.class looks like
@XmlRootElement(name = "Element1", namespace = "http://www.example.org/extension") public class Element1{ @XmlElement(name = "ElementB", namespace = "http://www.example.org/extension", required = true) protected List<ElementB> _elementB; but what I need would be:
... @XmlElement(name = "ElementB", namespace = "http://www.example.org/extern", required = true) protected List<ElementB> _elementB; or
... @XmlElement(name = "ElementB") protected List<ElementB> _elementB; So, how I get ElementB to have the namespace http://www.example.org/extern? Because with the other namespace I can't unmarschal an "Element1 xml node".
2.) In extension.xsd I only need ElementB, but jaxb (using eclipse) generates classes for all elements of extern.xsd. Can be specified which classes should be generated?
Thanks in advance!
No comments:
Post a Comment