Menu
Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
XML
parsing XML to DOM, validating against a local DTD, using Xerces under JAXP?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="bugbear" data-source="post: 768364"><p>Subject pretty much says it all. I'd like to</p><p>parse XML (duh!) using Xerces (because its fast,</p><p>and reliable, and comprehensive, and supports lots</p><p>of features).</p><p></p><p>I'd like to conform to standards as much as possible,</p><p>so I'd like to call Xerces under the JAXP API.</p><p></p><p>I'd like to validate the XML against a DTD, so that</p><p>errors are flagged up to the user, and I can transcribe</p><p>the DOM to my own data structures without (too much)</p><p>checking.</p><p></p><p>And I'd like to check aginst a local DTD so that parsing</p><p>XML doesn't cause Xerxes to try to download a DTD over</p><p>the 'net for each file (sloooow).</p><p></p><p>I'm working with j2sdk 1.4.2 and Xerces 2.5.0</p><p></p><p>This should be easy, right?</p><p>It isn't. As far as I can tell, the DocumentBuilder API</p><p><a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilder.html">http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilder.html</a></p><p>doesn't support any way of setting features. You have to do it in the</p><p>setAttribute() method in the Factory.</p><p><a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setAttribute(java.lang.String">http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setAttribute(java.lang.String</a>,</p><p>java.lang.Object)</p><p>But...</p><p>the Xerces documentaion says this API "cannot be relied on"</p><p><a href="http://xml.apache.org/xerces2-j/features.html">http://xml.apache.org/xerces2-j/features.html</a></p><p></p><p>I could get at it IFF I use a Sax parser (same Xerces page).</p><p>My desire to use a local copy of the DTD can also be addresses via</p><p>Xerces/SAX.</p><p></p><p>By defining an EntityResolver</p><p>and associating it with the DefaultHandler</p><p>passed into the SAXParser parse(...) method</p><p>I can persuade the DOCTYPE to be resolved off to a local</p><p>resource, as per this helpful page:</p><p><a href="http://doctypechanger.sourceforge.net/#doc.Other">http://doctypechanger.sourceforge.net/#doc.Other</a></p><p></p><p>(javadoc URLs</p><p><a href="http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/EntityResolver.html">http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/EntityResolver.html</a></p><p><a href="http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/helpers/DefaultHandler.html">http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/helpers/DefaultHandler.html</a></p><p><a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/SAXParser.html#parse(java.io.File">http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/SAXParser.html#parse(java.io.File</a>,</p><p>org.xml.sax.helpers.DefaultHandler))</p><p></p><p>But I'd rather use DOM; is it *really* this hard</p><p>to get Xerces to co-exist with JAXP?</p><p></p><p>One way around this is to define my own DOM</p><p>parser by wrapping a SAX Parser, and using a SAX ContenHandler that</p><p>simply builds up a Document object; I'm sure someone has done this</p><p>already...</p><p></p><p>But I'd like to just use Xerces "direct".</p><p></p><p>So - is there a way?</p><p></p><p>All hints, tips and links gratefully listened to.</p><p></p><p>BugBear</p></blockquote><p></p>
[QUOTE="bugbear, post: 768364"] Subject pretty much says it all. I'd like to parse XML (duh!) using Xerces (because its fast, and reliable, and comprehensive, and supports lots of features). I'd like to conform to standards as much as possible, so I'd like to call Xerces under the JAXP API. I'd like to validate the XML against a DTD, so that errors are flagged up to the user, and I can transcribe the DOM to my own data structures without (too much) checking. And I'd like to check aginst a local DTD so that parsing XML doesn't cause Xerxes to try to download a DTD over the 'net for each file (sloooow). I'm working with j2sdk 1.4.2 and Xerces 2.5.0 This should be easy, right? It isn't. As far as I can tell, the DocumentBuilder API [URL]http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilder.html[/URL] doesn't support any way of setting features. You have to do it in the setAttribute() method in the Factory. [URL]http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setAttribute(java.lang.String[/URL], java.lang.Object) But... the Xerces documentaion says this API "cannot be relied on" [URL]http://xml.apache.org/xerces2-j/features.html[/URL] I could get at it IFF I use a Sax parser (same Xerces page). My desire to use a local copy of the DTD can also be addresses via Xerces/SAX. By defining an EntityResolver and associating it with the DefaultHandler passed into the SAXParser parse(...) method I can persuade the DOCTYPE to be resolved off to a local resource, as per this helpful page: [URL]http://doctypechanger.sourceforge.net/#doc.Other[/URL] (javadoc URLs [URL]http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/EntityResolver.html[/URL] [URL]http://java.sun.com/j2se/1.4.2/docs/api/org/xml/sax/helpers/DefaultHandler.html[/URL] [URL]http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/SAXParser.html#parse(java.io.File[/URL], org.xml.sax.helpers.DefaultHandler)) But I'd rather use DOM; is it *really* this hard to get Xerces to co-exist with JAXP? One way around this is to define my own DOM parser by wrapping a SAX Parser, and using a SAX ContenHandler that simply builds up a Document object; I'm sure someone has done this already... But I'd like to just use Xerces "direct". So - is there a way? All hints, tips and links gratefully listened to. BugBear [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
XML
parsing XML to DOM, validating against a local DTD, using Xerces under JAXP?
Top