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
3. Simple types
  


Exercise 2 solution page 6 of 10



//Exercise 2 builds from Exercise 1
Lab1 lab1 = new Lab1();
XSDSchema schema = lab1.createSchema(xsdFile); //Schema from lab1

//Create global simple type with name="USState"
XSDSimpleTypeDefinition simpleType = XSDFactory.eINSTANCE.createXSDSimpleTypeDefinition();
simpleType.setName("USState");

//Set the base type to be a string
XSDSimpleTypeDefinition stringType = schema.getSchemaForSchema().
        resolveSimpleTypeDefinition(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001,"string");
simpleType.setBaseTypeDefinition(stringType);

//AK Enumeration
XSDEnumerationFacet akEnum = XSDFactory.eINSTANCE.createXSDEnumerationFacet();
akEnum.setLexicalValue("AK");
simpleType.getFacetContents().add(akEnum);

//AL Enumeration
XSDEnumerationFacet alEnum = XSDFactory.eINSTANCE.createXSDEnumerationFacet();
alEnum.setLexicalValue("AL");
simpleType.getFacetContents().add(alEnum);

//AR Enumeration
XSDEnumerationFacet arEnum = XSDFactory.eINSTANCE.createXSDEnumerationFacet();
arEnum.setLexicalValue("AR");
simpleType.getFacetContents().add(arEnum);

//Add the simple type to the root schema
schema.getContents().add(simpleType);

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

Main menuSection menuFeedbackPreviousNext
About IBM | Privacy | Legal | Contact