Utility to generate xsd from java class

I want to generate xsd for the next class

public class Node{ private String value; private List<Node> childrens; } 

What is the best utility to generate an xsd schema for such code

In general, I want to implement a simple tree. I already use jaxb to generate classes from the schema.

+7
source share
2 answers
+3
source

You can use the generateSchema API for JAXBContext to create an XML schema:

 import java.io.IOException; import javax.xml.bind.*; import javax.xml.transform.Result; import javax.xml.transform.stream.StreamResult; public class Demo { public static void main(String[] args) throws Exception { JAXBContext jc = JAXBContext.newInstance(Node.class); jc.generateSchema(new SchemaOutputResolver() { @Override public Result createOutput(String namespaceURI, String suggestedFileName) throws IOException { return new StreamResult(suggestedFileName); } }); } } 
+5
source

All Articles