Re: parsing XML file
- From: steph <steph@xxxxxxxxxxx>
- Date: Tue, 28 Aug 2007 19:36:11 +0200
Christine Mayer wrote:
Hi,
I've got an XML file, containing key /value pairs. First of all, I
want to validate the XML file by a XSD
Schema file I have. Finally, I want to read all text nodes and put the
key /value pairs into a HashMap.
Questions:
1. Which parser do you recomend?
2. How can I validate the XML file with my XSD Schema?
3. How can I access the text nodes?
if you want to "browse" your xml document you need to use a DOM api.
you can find an implementation here http://xerces.apache.org/xerces-j/
the drawback of this method is that you load the whole document in
memory and that the initial parsing is (relativly) slow.
an other option is to parse the document as a stream; known as SAX.
there is a SAX parser (crimson) embedeed in the Sun JRE.
unsing SAX, if you want to validate before loading, you have to parse
twice (ugly!), if not, you can validate and load data at the same time
but your process could fail before the end of the file (maybe unsafe).
I advise you to do it in one pass with a same way to fail using a
temporary Map and not the main one.
<code>mainMap.putAll(tmpMap)</code>
.
- References:
- parsing XML file
- From: Christine Mayer
- parsing XML file
- Prev by Date: Re: Inappropriate Subject
- Next by Date: Re: Recommended Java Design Pattern Books/Websites?
- Previous by thread: Re: parsing XML file
- Next by thread: Re: parsing XML file
- Index(es):
Relevant Pages
|