bravo14 Posted May 14, 2017 Share Posted May 14, 2017 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted May 14, 2017 Share Posted May 14, 2017 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. Quote Link to comment Share on other sites More sharing options...
fatkatie Posted May 16, 2017 Share Posted May 16, 2017 xpath tools heaven sent: Are you using one? I couldn't work with xpath without them. ddgo on sketchpath or xmlquire. There looks like there are quite a few tools out there. I read somewhere firebug even has support. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.