Hi, guys
I need to dynamically create type mapping to the below schema:
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://example.com/IPO"
targetNamespace="http://example.com/IPO">
<xsd:element name="purchaseOrder" type="PurchaseOrder"/>
<xsd:complexType name="PurchaseOrder">
<xsd:sequence>
<xsd:element name="shipTo" type="xsd:string" minOccurs="0"/>
<xsd:element name="billTo" type="xsd:string" minOccurs="0"/>
<xsd:element name="items" type="xsd:string" minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
Here is my code:
HelperContext helperContext = SDOUtil.createHelperContext();
DataFactory df = helperContext.getDataFactory();
DataObject typeDef = df.create("commonj.sdo", "Type");
typeDef.set("uri", "http://example.com/IPO");
typeDef.set("name", "PurchaseOrder");
DataObject propDef = typeDef.createDataObject("property");
propDef.set("name", "shipTo");
propDef.set("type",
helperContext.getTypeHelper().getType("commonj.sdo", "String"));
propDef = typeDef.createDataObject("property");
propDef.set("name", "billTo");
propDef.set("type",
helperContext.getTypeHelper().getType("commonj.sdo", "String"));
propDef = typeDef.createDataObject("property");
propDef.set("name", "items");
propDef.set("type",
helperContext.getTypeHelper().getType("commonj.sdo", "String"));
propDef.set("many", true);
Type type = helperContext.getTypeHelper().define(typeDef);
List types = new ArrayList<Type>();
types.add(type);
System.out.println(helperContext.getXSDHelper().generate(types));
The created type actually map to the below schema:
<xs:schema xmlns:sdo="commonj.sdo" xmlns:sdoJava="commonj.sdo/java"
xmlns:stn_1="http://example.com/IPO"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
attributeFormDefault="qualified" elementFormDefault="qualified"
targetNamespace="http://example.com/IPO">
<xs:complexType abstract="false" name="PurchaseOrder">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="items"/>
</xs:sequence>
<xs:attribute name="shipTo" type="xs:string"/>
<xs:attribute name="billTo" type="xs:string"/>
</xs:complexType>
<xs:element name="purchaseOrder" type="stn_1:PurchaseOrder"/>
</xs:schema>
What did I missed? I want "shipTo" and "billTo" to be elements contained
in sequence, not as attribute contained directly in complexType. Any
hint may be helpful. Thank you!
Regards,
Grovecai