Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > General Computer Support > Java read xml file

Reply
Thread Tools

Java read xml file

 
 
java_newbie java_newbie is offline
Junior Member
Join Date: May 2009
Posts: 3
 
      05-26-2009
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
 
Reply With Quote
 
 
 
 
torontolife torontolife is offline
Member
Join Date: Jun 2009
Posts: 33
 
      06-04-2009
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)
 
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
File.read(fname) vs. File.read(fname,File.size(fname)) Alex Dowad Ruby 4 05-01-2010 08:20 AM
Java - Read XML file from Java java_newbie Java 0 05-25-2009 10:22 PM
Problem to insert an XML-element by XSLT-converting from one XML-file into another XML-file jkflens XML 2 05-30-2006 09:41 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Valid xml to read from an xml file? Chumley Walrus ASP .Net 2 12-28-2005 10:02 PM



Advertisments