Solved

Displaying data from XML file

Posted on 2004-08-09
10
260 Views
Last Modified: 2010-04-17
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_value>
  </field>
- <field id="FirstName" taborder="2">
  <field_value>Isaac</field_value>
  </field>
- <field id="LastName" taborder="3">
  <field_value>Luo</field_value>
  </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_value>
  </field>
- <field id="FirstName" taborder="2">
  <field_value>Tom</field_value>
  </field>
- <field id="LastName" taborder="3">
  <field_value>Lee</field_value>
  </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.
0
Comment
Question by:blurSoul
  • 5
  • 4
10 Comments
 
LVL 1

Expert Comment

by:Shatai
ID: 11759779
How are you creating/programming the page?
0
 
LVL 4

Expert Comment

by:alikoank
ID: 11759985
Following xpath returns the customer info that belongs to Isaac Luo

Bookings/Customer/field[@id='FirstName'][field_value='Isaac']/../field[@id='LastName'][field_value='Luo']/..
0
 

Author Comment

by:blurSoul
ID: 11759986
They have to key in their email address and from there the information will be displayed. Can that be done?
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 4

Accepted Solution

by:
alikoank earned 125 total points
ID: 11759998
if you have email data in your XML file like this

<field id="email" taborder="3">
  <field_value>isaac@luo.com</field_value>
  </field>

it can be selected with following xpath

Bookings/Customer/field[@id='email'][field_value='isaac@luo.com']/..
0
 

Author Comment

by:blurSoul
ID: 11760002
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.
0
 

Author Comment

by:blurSoul
ID: 11760008
Oh. So thats the only line I need and thats it? Like the DB "Select From" line?
0
 

Author Comment

by:blurSoul
ID: 11760015
Just a question this "Bookings/Customer/field[@id='email'][field_value='isaac@luo.com']/.." what does the "/.." at the end do? Do I have to use it everytime?
0
 
LVL 4

Expert Comment

by:alikoank
ID: 11760018
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/

0
 
LVL 4

Expert Comment

by:alikoank
ID: 11760030
/.. means parent node just like in a directory tree. without it the query returns only <field> node that matches criteria.
0
 

Author Comment

by:blurSoul
ID: 11760063
Oh ok. Thanks. I'll give it a try.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question