Java read xml file

Discussion in 'General Computer Support' started by java_newbie, May 26, 2009.

  1. java_newbie

    java_newbie

    Joined:
    May 25, 2009
    Messages:
    1
    Hello all,

    I'm trying to read the contents of an XML file from my Java program.

    ==================================================
    logDay0.xml
    ==================================================

    <?xml version="1.0" ?>
    <root gmtdate="05-22-2009" gmttime="03:45:52" totalEvents="479">
    <event id="1" gmttimecode="1242884080" gmtdate="05-21-2009" gmttime="05:34:40" type="Added" category="DPI" msg="Heartbeat Lost" />
    <event id="2" gmttimecode="1242884130" gmtdate="05-21-2009" gmttime="05:35:30" type="Received" category="DPI" msg="splice_insert for source 0x0, event 000061D4, program 0, avail 0 of 0" />
    <event id="17" gmttimecode="1242885494" gmtdate="05-21-2009" gmttime="05:58:14" type="Received" category="DPI" msg="SCTE104 VANC message embedded for source 0x0, event 0x000061D5" />
    <event id="4" gmttimecode="1242884130" gmtdate="05-21-2009" gmttime="05:35:30" type="Received" category="DPI" msg="Relay #1 triggered by SCTE35 splice_insert for Source 0x00, Event 00025044" />
    <event id="7" gmttimecode="1242884130" gmtdate="05-21-2009" gmttime="05:35:30" type="Received" category="DPI" msg="GP output #2 triggered by SCTE35 splice_insert for Source 0x00, Event 00025044" />
    <event id="8" gmttimecode="1242884130" gmtdate="05-21-2009" gmttime="05:35:30" type="Received" category="DPI" msg="SCTE104 VANC message embedded for source 0x0, event 0x000061D4" />
    </root>
    ================================================== ==

    I want to extract info from the tag and after some parsing, display
    them as:

    event id=17 gmttimecode=1242885494 gmtdate=05-21-2009 gmttime=05:58:14 type=Received category=DPI msg=SCTE104 VANC message embedded for source 0x0, event 0x000061D5
    event id=8 gmttimecode=1242884130 gmtdate=05-21-2009 gmttime=05:35:30 type=Received category=DPI msg=SCTE104 VANC message embedded for source 0x0, event 0x000061D4

    I don't want anything fancy, just some ability to specify a file and extract specific tags that contain msg: SCTE104 xxxx and print out the results and ignore the tags with no SCTE104. A sample java program would be helpful.


    Thanks
     
    java_newbie, May 26, 2009
    #1
    1. Advertising

  2. java_newbie

    torontolife

    Joined:
    Jun 4, 2009
    Messages:
    32
    Don't reinvent the wheel, use a library instead!

    dom4j and JDOM are two nice XML libraries for Java, and you can parse XML as simply as calling a function.

    See dom4j.org and jdom.org (sorry, I can't post links due to this pesky forum thing)
     
    torontolife, Jun 4, 2009
    #2
    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. Tom Denford

    How to convert XML file to OPML File ...

    Tom Denford, Apr 24, 2005, in forum: Computer Support
    Replies:
    1
    Views:
    12,670
  2. datta.saru
    Replies:
    0
    Views:
    1,453
    datta.saru
    May 15, 2006
  3. sovan
    Replies:
    0
    Views:
    1,238
    sovan
    Jul 25, 2006
  4. sowmyask
    Replies:
    0
    Views:
    2,271
    sowmyask
    Apr 15, 2009
  5. yellowsocks
    Replies:
    0
    Views:
    2,775
    yellowsocks
    Jun 10, 2010
Loading...

Share This Page