I need to edit a xml-schema file (.xsd) within an eclipse plugin project (eclipse version is 4.2.2). Right now, I'm able to read the xsd IFile in my eclipse project using org.apache.xerces.xs.XSModel in a way like this:
private XSModel readXSDModelFromResource(IFile xsdFile) throws CoreException, ClassNotFoundException, InstantiationException, IllegalAccessException, ClassCastException {
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
XSImplementation xsImplementation = (XSImplementation) registry.getDOMImplementation("XS-Loader");
XSLoader schemaLoader = xsImplementation.createXSLoader(null);
LSInput input = new DOMInputImpl();
input.setBaseURI(xsdFile.getLocation().removeLastSegments(1).addTrailingSeparator().toOSString());
input.setSystemId(xsdFile.getFullPath().lastSegment());
input.setByteStream(xsdFile.getContents());
XSModel model = schemaLoader.load(input);
return model;
}
This is fine! My XSModel has the correct representation of the XML Schema, also following all the xsd:include tags.
But, I read here that
XSModel: a read-only interface that represents an XML Schema, which could be components from different namespaces.
And here that
XMLSchema is a lightweight Java object model that can be used to manipulate and generate XML schema representations. You can use it to read XML Schema (xsd) files into memory and analyze or modify them, or to create entirely new schemas from scratch.
Hence, since my needs are to add or delete elements, changing target namespaces and so on, my doubts are:
- how can I manipulate the XSModel? What is (if exists) the related read-write object/library?
- if i have to use Apache XMLSchema library, how can I import it into eclipse plugin project since the dependecies list for plugin.xml have nothing related to org.apache.ws.* package?
I'd like to avoid, if possile (I hope so :) ), the raw xml dom manipulation with DOM, SAX, DOM4J....
Thanks to all