Re: parsing XML file



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>
.



Relevant Pages

  • Re: parsing XML file
    ... want to validate the XML file by a XSD ... Schema file I have. ... The Java code to validate with an XSD schema is trivial. ...
    (comp.lang.java.programmer)
  • Re: Problem with ValidationEventHandler
    ... I've got a xml file and xsd with only one namespace - ... xsd the validationeventhandler show me only the first error. ... validate XML node by node, and to skip over nodes when you want (e.g. ...
    (microsoft.public.dotnet.languages.csharp)
  • Parsing XML against multiple complex XSD
    ... I have an XML file that I need to validate in code ... The schema definition is spread accross multiple XSD files ...
    (comp.lang.java.programmer)
  • Problem with ValidationEventHandler
    ... I've got a xml file and xsd with only one namespace - ... When I'm trying to validate this Xml with my ... xsd the validationeventhandler show me only the first error. ...
    (microsoft.public.dotnet.languages.csharp)
  • Problem with ValidationEventHandler
    ... I've got a xml file and xsd with only one namespace - ... When I'm trying to validate this Xml with my ... xsd the validationeventhandler show me only the first error. ...
    (microsoft.public.dotnet.xml)