我想使用org / w3 / _2001 / xmlschema的JAXB和ObjectFactory类生成以下XSD架构
<xs:element name="result">
<xs:complexType>
<xs:sequence>
<xs:element name="sfobject" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="id"/>
<xs:element type="xs:string" name="type"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
但我得到XSD:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="result">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element name="sfobject" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence/>
</xs:complexType>
</xs:element>
<xs:element type="xs:string" name="id"/>
<xs:element type="xs:string" name="type"/>
</xs:schema>
我无法在其他元素中添加一个元素。如何使用JAXB和ObjectFactory方法在Java中执行此操作。
示例代码:
列表schemaElementList = schema.getSimpleTypeOrComplexTypeOrGroup();
TopLevelElement resultElement = xsdObjFactory.createTopLevelElement();
resultElement.setName("result");
LocalComplexType resultCompType = xsdObjFactory.createLocalComplexType();
resultElement.setComplexType(resultCompType);
resultCompType.setSequence(expGroup);
Element sfElement = (Element)xsdObjFactory.createLocalElement();
sfElement.setName("sfobject");
sfElement.setMaxOccurs("unbounded");
sfElement.setMinOccurs(new BigInteger("0"));
LocalComplexType sfCompType = xsdObjFactory.createLocalComplexType();
sfElement.setComplexType(sfCompType);
schemaElementList.add(resultElement);