blurSoul
asked on
Displaying data from XML file
Hi experts,
I need help on this. I have an XML file with this: (I cut down on the length as its too long)
- <Bookings>
- <Customer>
- <field id="send" taborder="1">
<field_value>1</field_valu e>
</field>
- <field id="FirstName" taborder="2">
<field_value>Isaac</field_ value>
</field>
- <field id="LastName" taborder="3">
<field_value>Luo</field_va lue>
</field>
- <field id="address" taborder="4">
<field_value>1 Bergonia Drive</field_value>
</field>
- <field id="PCode" taborder="5">
<field_value>152001</field _value>
</field>
</Customer>
- <Customer>
- <field id="send" taborder="1">
<field_value>1</field_valu e>
</field>
- <field id="FirstName" taborder="2">
<field_value>Tom</field_va lue>
</field>
- <field id="LastName" taborder="3">
<field_value>Lee</field_va lue>
</field>
- <field id="address" taborder="4">
<field_value>Blk 179 Ang Mo KIo Ave 5</field_value>
</field>
- <field id="PCode" taborder="5">
<field_value>560179</field _value>
</field>
</Customer>
</Bookings>
Now, I'm doing a website and people may want to view their information. How do I extract only THIER information, say only Tom Lee and not display the other customers' information? For DB I know its the "select" statement. What about XML? Can it be done? The examples on the net all display the whole XML file contents onto the page.
I need help on this. I have an XML file with this: (I cut down on the length as its too long)
- <Bookings>
- <Customer>
- <field id="send" taborder="1">
<field_value>1</field_valu
</field>
- <field id="FirstName" taborder="2">
<field_value>Isaac</field_
</field>
- <field id="LastName" taborder="3">
<field_value>Luo</field_va
</field>
- <field id="address" taborder="4">
<field_value>1 Bergonia Drive</field_value>
</field>
- <field id="PCode" taborder="5">
<field_value>152001</field
</field>
</Customer>
- <Customer>
- <field id="send" taborder="1">
<field_value>1</field_valu
</field>
- <field id="FirstName" taborder="2">
<field_value>Tom</field_va
</field>
- <field id="LastName" taborder="3">
<field_value>Lee</field_va
</field>
- <field id="address" taborder="4">
<field_value>Blk 179 Ang Mo KIo Ave 5</field_value>
</field>
- <field id="PCode" taborder="5">
<field_value>560179</field
</field>
</Customer>
</Bookings>
Now, I'm doing a website and people may want to view their information. How do I extract only THIER information, say only Tom Lee and not display the other customers' information? For DB I know its the "select" statement. What about XML? Can it be done? The examples on the net all display the whole XML file contents onto the page.
How are you creating/programming the page?
Following xpath returns the customer info that belongs to Isaac Luo
Bookings/Customer/field[@i d='FirstNa me'][field _value='Is aac']/../f ield[@id=' LastName'] [field_val ue='Luo']/ ..
Bookings/Customer/field[@i
ASKER
They have to key in their email address and from there the information will be displayed. Can that be done?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
alikoank I don't really understand how that works. How come its so long? By the way I don't know xpath. First time seeing it.
ASKER
Oh. So thats the only line I need and thats it? Like the DB "Select From" line?
ASKER
Just a question this "Bookings/Customer/field[@ id='email' ][field_va lue='isaac @luo.com'] /.." what does the "/.." at the end do? Do I have to use it everytime?
yes, xpath is like select in database. it returns nodes that match your selection criteria. For more information plase take a look at:
http://www.w3schools.com/xpath/
http://www.w3schools.com/xpath/
/.. means parent node just like in a directory tree. without it the query returns only <field> node that matches criteria.
ASKER
Oh ok. Thanks. I'll give it a try.