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
tony_se - 28 Aug 2007 11:36 GMT
> Hi,
>
[quoted text clipped - 11 lines]
>
> Christine Mayer
Try JDOM
bugbear - 28 Aug 2007 12:38 GMT
>> Hi,
>>
[quoted text clipped - 13 lines]
>
> Try JDOM
JDOM doesn't appear to be a parser
http://www.jdom.org/docs/faq.html#a0360
BugBear
Arne Vajhøj - 01 Sep 2007 02:57 GMT
>>> I've got an XML file, containing key /value pairs. First of all, I
>>> want to validate the XML file by a XSD
[quoted text clipped - 15 lines]
>
> http://www.jdom.org/docs/faq.html#a0360
It wraps another parser.
But for the end user it does not matter much if the parser is
part of JDOM or external to JDOM.
Arne
steph - 28 Aug 2007 18:36 GMT
> Hi,
>
[quoted text clipped - 7 lines]
> 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>
Roedy Green - 28 Aug 2007 23:40 GMT
>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.
see http://mindprod.com/jgloss/xml.html
The Java code to validate with an XSD schema is trivial.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com