Parsing XML using JAVA

Discussion in 'Programming' started by ThaSniper, Sep 23, 2008.

  1. #1
    Hello.

    I have Java knowledge and I need to extract information from a .xml file. I thought I could create my custom program to do what I need.

    I've been reading around on the internet examples about how to do it in Java. But there are many different parsers classes and the usage is different. I've seen examples but I'm getting confused.

    If anyone have a java xml parser coded, that I could use, it would ease the trouble... I'd just have to shape it to my needs.

    I'd be happy with a program that would read all the XML fields and load them into some structure, like a Vector.

    Anyone?
     
    ThaSniper, Sep 23, 2008 IP
  2. leska

    leska Member

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    If you don't need to handle large XML files, look at DOM parsers. JDOM or DOM4J. If you need to have great performance, use StAX parsers.
     
    leska, Sep 26, 2008 IP
  3. megacontent

    megacontent Guest

    Messages:
    231
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have used JAXB in the past.

    You could always input the file using FileInputStream and then parse it line by line. I've done it in the past, but it's better to use JAXB or another parser to do it.
     
    megacontent, Sep 27, 2008 IP
  4. leska

    leska Member

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #4
    I think that parsing method depends on performed task. In one cases it will be better to use JAXB or JiBX, in another tasks it will be better to parse it by hand using DOM or SAX.
     
    leska, Oct 11, 2008 IP