Reputation: 1084
Using eclipse XSD API, I can load a schema file and then parse the related xsd components.
Now my question is, can i create a blank XSDElementDeclaration
component and set their properties without binding any schema file?
For example, I'd like to create a simple type element named "query":
<element name = "query" type = "xsd:string"/>
My code like this:
XSDSimpleTypeDefinition queryStr =XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
queryStr.setName("string");
queryStr.setTargetNamespace("http://www.w3.org/2001/XMLSchema");
XSDElementDeclaration queryEle = XSDFactory.eINSTANCE.createXSDElementDeclaration();
queryEle.setName("query");
queryEle.setTypeDefinition(queryStr);
I think the created queryEle
should be meet my requirement. But it seems the created element is incorrect when I returned it to other's use.
How can I create XSDElementDeclaration
directly using the API?
Upvotes: 1
Views: 182
Reputation: 1084
Still need create XSDParticle and set this element to particle:
XSDSchema schemaForSchema = XSDUtil.getSchemaForSchema(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);
XSDSimpleTypeDefinition queryType = schemaForSchema.resolveSimpleTypeDefinition(simpleTypeName);
XSDElementDeclaration queryEle = XSDFactory.eINSTANCE.createXSDElementDeclaration();
queryEle.setName("query");
queryEle.setTypeDefinition(queryType);
XSDParticle elementParticle = XSDFactory.eINSTANCE.createXSDParticle();
elementParticle.setMinOccurs(minOccurs);
elementParticle.setMaxOccurs(maxOccurs);
elementParticle.setContent(element);
....
//add the element to XSDModelGroup
modelGroup.getContents().add(elementParticle);
...
Upvotes: 1