...
ResourceSet resourceSet = new ResourceSetImpl();
// Register XML Factory implementation to handle .xml files
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put("xml", new XMLResourceFactoryImpl());
// Create empty resource with the given URI
Resource resource = resourceSet.createResource(URI
.createURI("./bookStore.xml"));
// Add bookStoreObject to contents list of the resource
resource.getContents().add(bookStoreEObject);
Map options = new HashMap();
options.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
try {
//save the resource (to stdout)
resource.save(System.out, options);
//save as doc
Document doc=((XMLResource)resource).save(null, options, null);
Element el=doc.getDocumentElement();
NodeList nodeList=el.getElementsByTagName("books");
System.out.println(nodeList+nodeList.item(0));
}
...
<bookStore:BookStore xmlns:bookStore="http:///com.ibm.dynamic.example.bookStore.ecore" owner="David Brown" location="Street#12, Top Town, NY">
<books name="Harry Potter and the Deathly Hallows" isbn="157221"/>
</bookStore:BookStore>