parsing XML file

C

Christine Mayer

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?

Thanks in advance,

Christine Mayer
 
T

tony_se

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?

Thanks in advance,

Christine Mayer

Try JDOM
 
S

steph

Christine said:
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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top