parsing XML file

Discussion in 'Java' started by Christine Mayer, Aug 28, 2007.

  1. 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
    Christine Mayer, Aug 28, 2007
    #1
    1. Advertising

  2. Christine Mayer

    tony_se Guest

    On Aug 28, 6:00 pm, 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?
    >
    > Thanks in advance,
    >
    > Christine Mayer


    Try JDOM
    tony_se, Aug 28, 2007
    #2
    1. Advertising

  3. Christine Mayer

    bugbear Guest

    tony_se wrote:
    > On Aug 28, 6:00 pm, 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?
    >>
    >> Thanks in advance,
    >>
    >> Christine Mayer

    >
    > Try JDOM
    >


    JDOM doesn't appear to be a parser

    http://www.jdom.org/docs/faq.html#a0360

    BugBear
    bugbear, Aug 28, 2007
    #3
  4. Christine Mayer

    steph Guest

    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>
    steph, Aug 28, 2007
    #4
  5. Christine Mayer

    Roedy Green Guest

    On Tue, 28 Aug 2007 03:00:15 -0700, Christine Mayer <>
    wrote, quoted or indirectly quoted someone who said :

    >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.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Aug 28, 2007
    #5
  6. bugbear wrote:
    > tony_se wrote:
    >> On Aug 28, 6:00 pm, Christine Mayer <> wrote:
    >>> 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
    >>

    >
    > JDOM doesn't appear to be a parser
    >
    > 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
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Sep 1, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jkflens
    Replies:
    2
    Views:
    1,448
    jkflens
    May 30, 2006
  2. Jason
    Replies:
    2
    Views:
    623
    Jason
    Apr 28, 2007
  3. John Levine
    Replies:
    0
    Views:
    717
    John Levine
    Feb 2, 2012
  4. PL
    Replies:
    2
    Views:
    217
    Brian McCauley
    Dec 14, 2004
  5. Erik Wasser
    Replies:
    5
    Views:
    437
    Peter J. Holzer
    Mar 5, 2006
Loading...

Share This Page