[英]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. 它创建了Java类但是我发现我的根类没有正确的名称,并且没有
@XmlRootElement
,它将它声明为根元素,这意味着当我使用类生成XML时,它没有正确形成。
XSD Schema: XSD架构:
<?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. 声明为全局元素一部分的匿名复杂类型将获得
@XmlRootElement
注释。 Others will have a @XmlElementDecl
annotation generated on the ObjectFactory
class. 其他人将在
ObjectFactory
类上生成@XmlElementDecl
注释。 This is because there may be more than one global element that corresponds to the same complex type. 这是因为可能存在多个对应于相同复杂类型的全局元素。
For More Information 欲获得更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.