3

I'm looking for a leightweight library that allows me to genereate an XSD from XML in Java (no commandline tool). I know that it is not a clean way to generate it, but in this case I need to do it. Also the XML is very simple in terms of structure.

I already looked into Trang, but there is no API documentation except how to call it from command line.

Also I checked out xsd-gen, but the issue with that library is that one would need to modify some package declrations in the source code which I couldn't find.

Any other suggestions?

2 Answers 2

16

I am the author of the tool xsd-gen. I converted the tool to be a library as well, 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 simple to use as a library within 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)); 
Sign up to request clarification or add additional context in comments.

4 Comments

Perfect timing - just looking for this :-)
Very helpful indeed!
To use this, we also need to add xom jar because it contain nu.xom.parsingException class, if you don't use then it will throw error.
Small warning - I have found that this does not find all child elements for large xml files.
3

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

  1. TypeInferenceUtil.java
  2. XsdGen.java

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") 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.