WebReference.com - Part 3 of Chapter 10 from Professional PHP4 XML, from Wrox Press Ltd (3/7) | WebReference

WebReference.com - Part 3 of Chapter 10 from Professional PHP4 XML, from Wrox Press Ltd (3/7)

To page 1To page 2current pageTo page 4To page 5To page 6To page 7
[previous] [next]

Professional PHP4 XML, Chapter 10: Putting It Together

Querying XML

If our data model is based on XML we'll be querying documents very often. Some examples of the need to query XML are:

Querying an XML document means that we should traverse the XML document looking for particular information; what we do with the information once it is found is beyond the scope of the problem.

Example

Here we'll present a simple example to check how to solve the same problem using different approaches. In this case our example will show an XML file describing cars. This is the XML document:

<cars>
  <car>
    <type>F1</type>
    <brand>Ferrari</brand>
    <model>X1</model>
    <maxspeed>305</maxspeed>
    <hp>800</hp>
  </car>
  <car>
    <type>F1</type>
    <brand>Williams</brand>
    <model>W89</model>
    <maxspeed>298</maxspeed>
    <hp>1000</hp>
  </car>

  <car>
    <type>F1</type>
    <brand>Brabham</brand>
    <model>B01</model>
    <maxspeed>311</maxspeed>
    <hp>1020</hp>
  </car>
</cars>

And the query will be: "Find brand and model of F1 cars that can run at more than 300 kmh".

We have the following options to query an XML document:


To page 1To page 2current pageTo page 4To page 5To page 6To page 7
[previous] [next]

Created: August 26, 2002
Revised: August 26, 2002

URL: https://webreference.com/programming/php/php4xml/chap10/3/3.html