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
2. Overview of XML Schema documents
  


Exercise 1 solution page 3 of 5


 
//Get the URI of the model file. URI fileURI 
= URI.createPlatformResourceURI(xsdFile.getFullPath().toString());

//Create a resource set to manage the different resources
ResourceSet resourceSet = new ResourceSetImpl();

//Create a resource for this file.      
Resource resource = resourceSet.createResource(fileURI);

//Create the root XSDSchema object
XSDSchema schema = XSDFactory.eINSTANCE.createXSDSchema();

//Set the target namespace of the given schema document to
schema.setTargetNamespace("http://www.eclipse.org/xsd/examples/po");

java.util.Map qNamePrefixToNamespaceMap = schema.getQNamePrefixToNamespaceMap();
qNamePrefixToNamespaceMap.put(schema.getSchemaForSchemaQNamePrefix(),
        XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001);

//put the following namespace in the root schema namespace map
qNamePrefixToNamespaceMap.put("po", schema.getTargetNamespace());

//We call updateElement to synchronize the MOF model with the underlying DOM model
//This should only have to be done after creating a new model
schema.updateElement();

//Add the root schema to the resource that was created above
resource.getContents().add(schema);

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

Main menuSection menuFeedbackPreviousNext
About IBM | Privacy | Legal | Contact