简体   繁体   中英

JAXB converting XSD to Java classes

When I run the following command:

xjc -b xmlSchema.xjb -d src -p com.q1labs.qa.xmlgenerator.model.generatedxmlclasses xmlSchema.xsd

It creates Java classes however I've found that my root class does not have the correct name and does not have @XmlRootElement which declares it as a root element which means when I use the classes to generate XML it is not formed properly.

XSD Schema:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified"
    elementFormDefault="qualified" targetNamespace="http://ibm.org/seleniumframework"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="Test" type="sel:TestType" xmlns:sel="http://ibm.org/seleniumframework"/>

    <xs:complexType name="TestType">
        <xs:choice minOccurs="1" maxOccurs="unbounded">
            <xs:element type="sel:Option1" name="Option1" xmlns:sel="http://ibm.org/seleniumframework"/>
            <xs:element type="sel:Option2" name="Option2" xmlns:sel="http://ibm.org/seleniumframework"/>
            <xs:element type="sel:Option3" name="Option3" xmlns:sel="http://ibm.org/seleniumframework"/>
        </xs:choice>
    </xs:complexType>

This is the output I am getting:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<testType xmlns="http://ibm.org/seleniumframework"/>

Generated classes correspond to complex types. Anonymous complex types that are declared as part of global elements will get an @XmlRootElement annotation. Others will have a @XmlElementDecl annotation generated on the ObjectFactory class. This is because there may be more than one global element that corresponds to the same complex type.

For More Information

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM