This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes xerces : Parsingproblem when Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xerces : Parsingproblem when "include" one or more Schema in another" Watch "xerces : Parsingproblem when "include" one or more Schema in another" New topic

xerces : Parsingproblem when "include" one or more Schema in another

Sascha Henning

Joined: Dec 18, 2003
Posts: 10
My problem is that i parse an xml-document and validate it against a schema. but the schema has multiple other schemas included (i'm using "include" not "import" because all schemas using the same namespace). and the sax parser (from xerces) can't find these schemas, because he is obviously searching in the wrong directory - in fact in the dirctory of the application, not in the directory of the including schema. the path, within the "include" attribute is given relativ to the including schema.
i'm using java 1.3.1 and have tried different xerces versions. With xerces 2.0.0 and higher, the sax parser seems not to validate at all. xerces 1.4.4 do validate but doesn't find the included schemas.
here is the java code:
SAXParser saxParser = new SAXParser();
InputStream ioStream =null;
("", true);
("", true);
InputStreamReader inputstream = new InputStreamReader(m_oStream,"UTF-8");
InputSource inputsource = new InputSource(inputstream);

heres a fragment of the including schema (Reply.xsd) (against this an xml file is validated)
<xs:schema targetNamespace="" xmlns="" xmlns:xs="" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:include schemaLocation="./KOM.xsd"/>
<xs:include schemaLocation="./Ort.xsd"/>
<xs:element name="Reply">
<xs:complexType name="reply">
<xs:element name="AKOM" type="auditkom" minOccurs="0"/>
<xs:element name="AOrt" type="auditort" minOccurs="0"/>
these to schemas (KOM, Ort) were not found, when the parser validates an xml file. all schemas are in the same dirctory (an other then the application directory). and the absolut path to the Reply.xsd (which is found) is given in the xml file.
can't sax from xerces handle "include" from xml-schema? or is there a version wich can?
Thanks & Regards,
raja guthi

Joined: Dec 23, 2003
Posts: 4
ur way of approach is very good in programming....when we r speaking about the parsers,U need to use the latest versions in ur far as UR code in java is concerned, it is absolutely correct and the problem is with the parser....u have tried with sax parser which is not handling the "include" from xml-schema, but have U tried "MSXML 4.0" india,iam using using this parser and am much comfortable using this one and why dont U try out for this....
this is the only parser which can help U, if not there's no other parser which can handle ur "include" attrib.....
bye sascha,
have a nice day.
with regards,
Sascha Henning

Joined: Dec 18, 2003
Posts: 10
hi, raja.
thanks for reply! i have looked for "MSXML 4.0" and i've found it. But i need to use it, in an java-application and i have not found any java libaries for the parser. if i want only validate an xml-file, i use "XML-Spy". and this tool has no problem with "include" and a relative path. but i need a solution for java-applications. thats the point. xerces has no problem with "include" if i use an absolut path to the schema (only relative its a problem)
So, is there a way to use "MSXML 4.0" (or any other parser)for java to solve the problem?
thanks & regards
raja guthi

Joined: Dec 23, 2003
Posts: 4
i gone through many books to find out a solution for ur problem after reading ur message...atlast, this is what I found in a book....
XML Parser for Java(XML 4.0,as it sometimes called) has an interface that allows U to take a string of XML-formatted text,pick the XML,tags out of it and use those tags as ur keys for extracting the tagged information. It seperates U from the need to deal with the string text directly-there's no need to foolwith the text stringdirectly. Whaz more,XML Parser for Java supports the XML Namespace standard.....
even after this, if U find difficult in ur code to execute the i can say that its impossible to use the "include" attrib in ur java code....
sascha, iam j ust a student at NIIT in INDIA....may be, i may go wrong somewhere but forgive me if I had redirected ur mind....
this is the maximum i can think of and if U found any solution, dont forget to mail me at:
waiting for ur mail...
with affeciton,
Have you checked out Aspose?
subject: xerces : Parsingproblem when "include" one or more Schema in another
It's not a secret anymore!