Go Back   Velocity Reviews > General Computer Discussion > General Help Related Topics
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

General Help Related Topics - Java read xml file

 
Thread Tools Search this Thread
Old 05-26-2009, 03:40 AM   #1
Default Java read xml file


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
java_newbie is offline   Reply With Quote
Old 06-04-2009, 02:30 AM   #2
torontolife
Member
 
Join Date: Jun 2009
Posts: 34
Default
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
torontolife is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46