473,394 Members | 1,770 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

parsing XML to DOM, validating against a local DTD, using Xerces under JAXP?

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
http://java.sun.com/j2se/1.4.2/docs/...ntBuilder.html
doesn't support any way of setting features. You have to do it in the
setAttribute() method in the Factory.
http://java.sun.com/j2se/1.4.2/docs/...va.lang.String,
java.lang.Object)
But...
the Xerces documentaion says this API "cannot be relied on"
http://xml.apache.org/xerces2-j/features.html

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:
http://doctypechanger.sourceforge.net/#doc.Other

(javadoc URLs
http://java.sun.com/j2se/1.4.2/docs/...yResolver.html
http://java.sun.com/j2se/1.4.2/docs/...ltHandler.html
http://java.sun.com/j2se/1.4.2/docs/...e(java.io.File,
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
Jul 17 '05 #1
0 4235

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bugbear | last post by:
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...
1
by: scorpion | last post by:
I have this problem that an xml instance is validated correctly by xml tools, but not with my simple code, by setting the validating flag to true. --------------- Schema...
4
by: joes | last post by:
Hello there I tried for several days to get a simple validation with xml schema & xerces working. Goal for me is tuse JAXP and not specific Xerces classes. I don't get the point what I am doing...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
18
by: jacksu | last post by:
I have a simple program to run xpath with xerces 1_2_7 XPathFactory factory = XPathFactory.newInstance(); XPath xPath = factory.newXPath(); XPathExpression xp = xPath.compile(strXpr);...
0
by: june | last post by:
Hi, I have a big problem with parsing HTML into a XHTML using Cberneko to validate the html. First I tried to work with a HTML-File. This solutions works fine: String aHTMLFile =...
1
by: christian.eickhoff | last post by:
Hi, I have a general question regarding the parsing of XSD files, referenced within the namespace using Apache Xerces 2.7.0 (CDT). My current c++ application can parse and validate an XML file...
0
by: jimmy Zhang | last post by:
VTD-XML (http://vtd-xml.sf.net) may also be interesting to you "Martin Honnen" <mahotrash@yahoo.dewrote in message news:47cd3ee6$0$25510$9b4e6d93@newsspool1.arcor-online.net...
1
by: Sidhartha | last post by:
Hi, I am facing a problem while parsing local language characters using sax parser. We use DOM to parse and SAX to read the source. But when our application parses strings with local language...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.