Generate XSD from XML programmatically in Java

I am looking for a library with a light drawing that allows me to generate XSD from XML in Java (without a command line tool). I know that this is not a clean way to generate it, but in this case I need to do this. XML is also very simple in terms of structure.

I already studied Trang, but there is no API documentation except to call it from the command line.

I also checked xsd-gen, but the problem with this library is that you will need to change some package declarations in the source code that I could not find.

Any other suggestions?

+1
source share
2 answers

I am the author of the xsd-gen tool. I also turned the tool into a library and uploaded the artifact to Maven Central:

<dependency> <groupId>org.wiztools</groupId> <artifactId>xsd-gen</artifactId> <version>0.2.1</version> </dependency> 

Now it is easy to use as a library in your application:

 import org.wiztools.xsdgen.XsdGen; import java.io.File; import java.io.FileOutputStream; ... XsdGen gen = new XsdGen(); gen.parse(new File("in.xml")); File out = new File("out.xsd"); gen.write(new FileOutputStream(out)); 
+12
source

I have included the xsd-gen source code and it worked for me. You only need

  • TypeInferenceUtil.java
  • XsdGen.java

In the package declarations I used (for Gradle) were:

 compile("com.io7m.xom:xom:1.2.10") compile("org.wiztools.commons:wiztools-commons-lib:0.4.1") 
+2
source

All Articles