File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes XSD Parser, XML Parsers doesn't work because XSD can be written different ways Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSD Parser, XML Parsers doesn Watch "XSD Parser, XML Parsers doesn New topic
Author

XSD Parser, XML Parsers doesn't work because XSD can be written different ways

Pratap koritala
Ranch Hand

Joined: Sep 27, 2006
Posts: 252
I want to find the root Type of the XSD ( You know the root node of the corresponding XML, But I don't have it's XML, just XSD)
I need to identify the root type, The normal XML ( XSD also a type of XML) doesn't work simply because you can write same XSD in different ways.
http://www.w3schools.com/schema/schema_example.asp


I tried XSOM, Apache XMLBeans ( There is a bug in programatically loading the xsd in it) and http://ws.apache.org/commons/xmlschema20/
But, nothing seems to work for above.

It is not that it cannot be done, But I don't want to reinvent this wheel.
Any help would be highly appreciated.

Chris Gage
Greenhorn

Joined: Mar 23, 2005
Posts: 17

I have been looking at a few of mine, and I think if you only have the XSD you may have to go back to basics -- the root tag has no REQUIRED identifying mark -- it is the only element tag that is neither a simple element nor contained within another complex element.

So use old-fashioned W3C DOM and parse your XSD as normal XML, then walk the tree and build a Map of all the element names, then walk the tree again and delete from the map:

-- all simple elements
-- all elements that occur inside another element.

You should be left with one element in your Map ...
 
wood burning stoves
 
subject: XSD Parser, XML Parsers doesn't work because XSD can be written different ways
 
Similar Threads
Unmarshall with JAXB Error
Newbie to Axis webservices
java.io.IOException: Type {http://lang.java}Exception is referenced but not defined.
javax.xml.validation doubt!
Difference between Schema and DTD?