tags:

views:

63

answers:

3

I have an XML document below:

 <wave waveID="1">
    <well wellID="1" wellName="A1">
      <oneDataSet>
        <rawData>0.1123975676</rawData>
      </oneDataSet>
    </well>
    ... more wellID's and rawData continues here...

In general terms, what's the best way to read the rawData, should I grab the node containing the well waveID=1 and then loop through that tree finding the rawData for each wellID? I'm new to XML and a little confused about the best way to read trees.

+1  A: 

There are two kinds of XML parsers you can use. The DOM approach (which you have tried in your other post about XPath) is a DOM approach. Here the XML document is loaded into memory at once and you use XPath expressions to pick out the pieces of data you want. The other approach is SAX. With SAX, you implement callback methods which are called by the parser as it goes through your document. This is more of an event-based model. the advantage here is that you do not need to consume a lot of memory by loading the entire document into memory at once.

darren
A: 

If you are using .NET languages, the simplest way to access XML information is by using the DataSet object. You create a DataSet object, then use the .ReadXML() method on your XML file and it parses that information into a set of DataTables which are more easily parsed through than the raw XML.

Ron

Ron Savage
-1: DataSet doesn't work for all XML patterns, only those which map to a Relational pattern.
John Saunders
I've yet to find an XML file that couldn't be loaded into a DataSet. Do you have an example?
Ron Savage
Here is a toy app I put together that edits XML files parsed into DataSets you can use to test with: http://dot-dash-dot.com/files/WTFXMLSetup_1_8_0.msi.
Ron Savage
A: 

try JLIbs SAX-Java binding

Santhosh Kumar T