Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java API to parse XSD schema file [closed]

Tags:

java

xml

xsd

Is there a Java API to parse an XSD schema file?

I found XSOM, but it doesn't seem to be maintained anymore.

like image 787
Henryk Konsek Avatar asked Oct 22 '10 12:10

Henryk Konsek


People also ask

How do I get an XSD file from XML?

With the desired XML document opened in the active editor tab, choose Tools | XML Actions | Generate XSD Schema from XML File on the main menu. The Generate Schema From Instance Document dialog box opens. and select the desired file in the dialog that opens.

What is XSD in API?

xsd file that maps XML elements and attributes to objects and properties. You can use this code to help you create XML blocks using typed code, and to deserialize and serialize data from REST API requests and responses.


1 Answers

Using standard JDK 6:

System.setProperty(DOMImplementationRegistry.PROPERTY, "com.sun.org.apache.xerces.internal.dom.DOMXSImplementationSourceImpl");
DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); 
com.sun.org.apache.xerces.internal.impl.xs.XSImplementationImpl impl = (XSImplementationImpl) registry.getDOMImplementation("XS-Loader");
XSLoader schemaLoader = impl.createXSLoader(null);
XSModel model = schemaLoader.loadURI("src/test/resources/my.xsd");
like image 75
emicklei Avatar answered Oct 13 '22 07:10

emicklei