简体   繁体   中英

How can I access XML elements and attributes?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM