Read XML

From Progzoo
Revision as of 15:50, 31 December 2007 by Andr3w (talk | contribs) (New page: <div style="float:right">The file [../bbc.xml bbc.xml] is as shown: <pre style="width:80ex;border-style:solid;border-width:thin;"> <world> <region id='Europe'> <country id=...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
The file

[../bbc.xml bbc.xml] is as shown:

<world>
<region id='Europe'>
<country id='de' name='Germany' pop='82000000'/>
<country id='fr' name='France'  pop='60000000'/>
</region>
<region id='Asia'>
<country id='cn' name='China' pop='1300000000'/>
</region>
</world>

The XPath expression //country[@id='fr']/@pop find the country node that has attribute id set to 'fr', it returns the value of the pop attribute.

The value returned should be 60 million.

Load a DOM document and apply an XPath expression

You load the XML file via the DocumentBuilderFactory, DocumentBuilder and parser. The xPath object can be used on this to evaluate the XPath expression.

[Font] [Default] [Show] [Resize] [History] [Profile]