views:

36

answers:

2

Given a few hundred java source files how can I generate an xsd schema that describes their class hierarchy, attributes and methods?

Most of the resources I've seen describe how to convert java to xml given the schema but how is that schema created? I did find Simple but that requires me to alter the source which I am not allowed to do.

+1  A: 

Apache axis provides the java2wsdl tool. Sure, you didn't ask for a wsdl but this tool should generate schemas (as needed) too.

So it's worth trying: implement some dummy interfaces with methods, that just use the types from your 'hundreds' of files, generate a wsdl and delete everything but the schemas.

Andreas_D
+1 not elegant, but pragmatic, although I'd prefer CXF ( http://www.opendocs.net/apache/cxf/2.2.4/java-to-wsdl.html ). The generated schemas are better, especially when enums are involved ( https://issues.apache.org/jira/browse/AXIS2-2766 )
seanizer
A: 

XSD schemas in themselves are recipies allowing a program to say whether a given XML document "conforms"/"does not conform" to the schema.

For this to make sense for Java classes, you have to define a conversion scheme from Java source to XML, and that XML format can then have an XSD, which may or may not be easily derivable programatically.

What Java -> XML mapping do you use?

Thorbjørn Ravn Andersen
hmm... I think I've confused myself then. What I need is to create some sort of file that I can describe each class e.g.public class Test extends X { private int a; }should show something like<class name="Test" inheritsFrom="X"> <attribute name="a" type="int"/></class>I dont know what that Java to XML mapping thing is?
feelie
You are describing a Java -> XML mapping. I have not seen any (which does not mean they do not exist), but I believe that if you do a XML files by hand and work with them you very rapidly find out what works and what doesn't.
Thorbjørn Ravn Andersen