Pages: [1]   Go Down
Author Topic: Reading and Parsing XML using XPath  (Read 502 times)
bynary
Guest
« on: February 09, 2009, 06:11:03 AM »

I am trying to use an ID retrieved from the querystring to get a node from an xml file.  I then need to extract each child node from that node into a variable.  Here's my code:

Code:
<?php 
$carid=$_GET['id'];

$xml simplexml_load_file("xml/inventory.xml");
$car $xml->xpath("/dataroot/XMLUpdateQuery[IDsuffix='$carid']");
$year $car->xpath("YEAR");
$model $car->xpath("MODEL");
$make $car->xpath("MAKE");
$price $car->xpath("ASKINGPRICE");
$color $car->xpath("COLOR");
$comments $car->xpath("COMMENTS");
$milesbeginning $car->xpath("MILESBEGINNING");
?>

I know this isn't right, this just illustrates what I'm trying to do.  Any help would be appreciated.
Report to moderator   Logged

erothchild
Guest
« Reply #1 on: February 10, 2009, 04:38:41 AM »

I am trying to use an ID retrieved from the querystring to get a node from an xml file.  I then need to extract each child node from that node into a variable.  Here's my code:

Code:

<?php
   $carid=$_GET['id'];   
         
   $xml = simplexml_load_file("xml/inventory.xml");   
   $car = $xml->xpath("/dataroot/XMLUpdateQuery[IDsuffix='$carid']");
   $year = $car->xpath("YEAR");
   $model = $car->xpath("MODEL");
   $make = $car->xpath("MAKE");
   $price = $car->xpath("ASKINGPRICE");
   $color = $car->xpath("COLOR");
   $comments = $car->xpath("COMMENTS");
   $milesbeginning = $car->xpath("MILESBEGINNING");
?>


I know this isn't right, this just illustrates what I'm trying to do.  Any help would be appreciated.
Report to moderator   Logged

Pages: [1]   Go Up
Print
 
Jump to:  

Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC | Theme Kani By Fussilet

Page created in 0.032 seconds with 19 queries.