Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 16th, 2006, 4:22 AM   #1
Eleo
Newbie
 
Join Date: Feb 2006
Posts: 6
Rep Power: 0 Eleo is on a distinguished road
Find a matching element in an XML file

I've got a pretty large XML file containing a list of optical drives and their read offsets (what those are specifically is pretty inconsequential to what I'm trying to do at the moment so don't let it confuse you.)

<drivelist>
  <drive>
    <name>MemorexDVDMAXX1648AJ</name>
    <offset>+594</offset>
  </drive>
</drivelist>

Then in my program I want to find one of the drive elements based on a string (string driveName = MemorexDVDMAXX1648AJ and then get the offset element and store it as an integer...

Now, I've Googled, and I've looked at a lot of XML tutorials and most of them are confusing the hell out of me. They all seem to go about things differently; some approaches are too complex or too long. I'm looking for a simple solution and I'm wondering if one exists since this is a read-only operation.

That said I would like to point out that the XML file itself is 4100 lines or so, and the method that is to be called to try to find a said drive in the XML file is going to be called perhaps hundreds of times. I looked through my Java book and it said there are two approaches to XML, DOM or SAX. Given the size of the XML file, I don't know if I should take the DOM or SAX route as it seems like a question of do I want to use a lot of processing power or a lot of RAM...

I can already tell this thread is going to confuse some people... Can anyone help me out here?
Eleo is offline   Reply With Quote
Old Feb 16th, 2006, 6:26 AM   #2
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
Could be done in a few lines using the XML namespace and XPath. Check out w3schools for an xpath tutorial.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Feb 16th, 2006, 8:25 PM   #3
Eleo
Newbie
 
Join Date: Feb 2006
Posts: 6
Rep Power: 0 Eleo is on a distinguished road
Thanks, that worked well.
Eleo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:57 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC