![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2006
Posts: 6
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#2 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
Could be done in a few lines using the XML namespace and XPath. Check out w3schools for an xpath tutorial.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270 |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Feb 2006
Posts: 6
Rep Power: 0
![]() |
Thanks, that worked well.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|