Java Reference
In-Depth Information
aisle 7. Walk two meters down the aisle. Pick up a bag of sugar. Walk to a checkout
counter.Payforthesugar.Retraceyourstepshome.”Mostpeoplewouldexpecttore-
ceivetheshorterinstruction,andwouldprobablyhaveyoucommittedtoaninstitution
if you made a habit out of providing the longer set of instructions.
Traversing a DOM tree of nodes is similar to providing the longer sequence of in-
structions.Incontrast,XPathletsyoutraversethistreeviaasuccinctinstruction.Tosee
thisdifferenceforyourself,considerascenariowhereyouhaveanXML-basedcontacts
document that lists your various professional contacts. Listing 10-20 presents a trivial
example of such a document.
Listing 10-20. XML-based contacts database
<?xml version="1.0"?>
<contacts>
<contact>
<name>John Doe</name>
<city>Chicago</city>
<city>Denver</city>
</contact>
<contact>
<name>Jane Doe</name>
<city>New York</city>
</contact>
<contact>
<name>Sandra Smith</name>
<city>Denver</city>
<city>Miami</city>
</contact>
<contact>
<name>Bob Jones</name>
<city>Chicago</city>
</contact>
</contacts>
Listing 10-20 reveals a simple XML grammar consisting of a contacts root ele-
mentthatcontainsasequenceof contact elements.Each contact elementcontains
one name elementandoneormore city elements(yourcontacttravelsfrequentlyand
Search WWH ::




Custom Search