Jump to content

SimpleXMLElement::xpath(): Invalid expression in


bravo14

Recommended Posts

Hi

 

I have an XML file listing vehicle details, one record looks like

 

 

<VehicleDataFeed>
<VehicleRecord>
<GUID>0dc50ce0-32e2-4785-a6a5-266071944792</GUID>
<ReferenceID>0002878523</ReferenceID>
<CompanyID>2</CompanyID>
<DivisionID>2</DivisionID>
<BranchID>2</BranchID>
<Location>Auction</Location>
<VehicleRecordID>890058</VehicleRecordID>
<StockNumber>BU101206</StockNumber>
<RegistrationNumber>SL61 TUA</RegistrationNumber>
<RegistrationDate>2011-09-29T00:00:00+01:00</RegistrationDate>
<MakeDescription>ALFA ROMEO</MakeDescription>
<ModelDescription>GIULIETTA</ModelDescription>
<SpecDescription>Veloce Tb</SpecDescription>
<Colour>Silver</Colour>
<BodyStyle>5 Door</BodyStyle>
<Transmission>Manual</Transmission>
<EngineSize>1368</EngineSize>
<FuelType>Petrol</FuelType>
<Mileage>40610</Mileage>
<RetailPrice>7500.00</RetailPrice>
<RetailPricePreVAT>7500.00</RetailPricePreVAT>
<VehicleType>Passenger</VehicleType>
<Qualifying>N</Qualifying>
<Profile>Trade</Profile>
<InternetPrice>7500.00</InternetPrice>
<Options>
<option>ABS</option>
<option> Alloy Wheels</option>
<option> Adjustable Steering Colmn</option>
<option> Air Conditioning</option>
<option> C D Player</option>
<option> Height Adjustable Drivers Seat</option>
<option> Multiple Airbags</option>
<option> Remote Central Locking</option>
</Options>
<InternetNotes />
<PreviousOwners>1</PreviousOwners>
<VehicleCode />
</VehicleRecord>

 

I am trying to search for a record on vehicle record id using the following

 
<?php
if(!isset($_GET['GUID']) && ($_GET['REF']) && ($_GET['VehID'])){
    header('Location: Vehicles.php');
}
else{
    $guid = $_GET['GUID'];
    $ref = $_GET['REF'];
    $vId = $_GET['VehID'];
}
?>
<?php
$url = "url to xml file";
//echo $url;
$vehicles =simplexml_load_file($url);
$value = $vehicles->xpath("string(//VehicleRecord/VehicleRecordID[contains(text(), $vId)]");

if(count($value) ==0) { // if found
header('Location:Vehicles.php');
}
?>

 

But am getting the following errors

 

 

Warning: SimpleXMLElement::xpath(): Invalid expression in /Applications/MAMP/htdocs/VehicleSearch/vehicle.php on line 19

Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in /Applications/MAMP/htdocs/VehicleSearch/vehicle.php on line 19
Link to comment
Share on other sites

I assume you're looking for a VehicleRecord that matches the ID given? That XQuery expression isn't really what it should be. Try

"//VehicleRecord[VehicleRecordID='" . (int)$vId . "']"
That's literally all the s that have a with the text value of $vId (which is forced to an integer to avoid an injection attack). You can count() the return value too.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.