Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : XML : Education - Tutorials
XML Schema Infoset Model, Part 2
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
5. Content models
  


Exercise 4 solution page 4 of 6



//Exercise 4 builds from Exercise 3
Lab3 lab3 = new Lab3();
XSDSchema schema = lab3.createSchema(xsdFile); //Schema from lab 3

//Create global complex type with name = "PurchaseOrderType"
XSDComplexTypeDefinition complexType = XSDFactory.eINSTANCE.createXSDComplexTypeDefinition();
complexType.setName("PurchaseOrderType");

XSDParticle particle = XSDFactory.eINSTANCE.createXSDParticle();

//Create a sequence model group
XSDModelGroup modelGroup = XSDFactory.eINSTANCE.createXSDModelGroup();
modelGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL);

//Add the model group to the particle
particle.setContent(modelGroup);

//Set the contents of the complex type to be the particle
complexType.setContent(particle);

//Add the complex type to the root schema
schema.getContents().add(complexType);

// Save the contents of the resource to the file system.
schema.eResource().save(Collections.EMPTY_MAP);                                 
                                        

Main menuSection menuFeedbackPreviousNext
About IBM | Privacy | Legal | Contact