Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Issue 1

Status
Not open for further replies.

Brianfree

Programmer
Feb 6, 2008
220
GB
Hi, i have some test code that doesn't work i done get any error messages or anything, please can someone help!!

I have changed username and passwords etc.. for security reasons!

Code:
<?php 
 
  $xml = simplexml_load_file("[URL unfurl="true"]http://www.hpixml.com/servlet/HpiGate1_0?efxid=xxxxxx&password=yyyyyy&initials=bgr&function=SEARCH&vrm=abc1234&XML=YES&product=KT001");[/URL]

?>

<?php 
	echo "KtypeNr: " . $xml->KTypeNr . "\n"; 
?>
 
Hi, i have tweaked the code slightly and now it returns the names of each section but not the data within...

Code:
<?xml version="1.0" encoding="ISO-8859-1"?>

<?php
ini_set('display_errors','on');
error_reporting(E_ALL);

$xml = simplexml_load_file("[URL unfurl="true"]http://www.hpixml.com/servlet/HpiGate1_0?efxid=xxxxxx&password=yyyyyy&initials=bgr&function=SEARCH&vrm=abc1234&XML=YES&product=KT001");[/URL]

echo $xml->getName() . "<br />";

foreach($xml->children() as $child)
  {
  echo $child->getName() . ": " . $child . "<br />";
  }
?>

This is the result i get...

Code:
HPICheck_Query

Section_07:
Basic:
FirstReg:
Extended:
Additional:
Keeper:
KtypeData:
Summary:
Misc_Data:

There are sections within sections, think this is where the problem may be??

Cant i just request one of the values i am looking for and echo it?

Many thanks,

Brian
 
please post the xml response from a typical query
 
Hi, if i copy and paste the following into the address bar
(have changed private information for security reasons..)


Code:
[URL unfurl="true"]http://www.hpixml.com/servlet/HpiGate1_0?efxid=xxxxxx&password=yyyyyy&initials=bgr&function=SEARCH&vrm=abc1234&XML=YES&product=KT001[/URL]


i get the following results...

Code:
<?xml version="1.0"?><HPICheck_Query VRM="zbc123" VIN="vfdfgdgdfgfdgf">
<Section_07>
<enquiry_number>000001</enquiry_number>
<product_code>KT001</product_code>
</Section_07>
<Basic>
<Vrm>zbc123
</Vrm>
<Fuel>Petrol</Fuel>
<Transmission>5 Speed Manual Petrol</Transmission>
<Make><![CDATA[ROVER]]>
</Make>
<Model><![CDATA[25 IL 16V]]>
</Model><Engine_No>xxxxxxxxxx</Engine_No><DVLA_Body_Plan_Description>5 Door Hatchback</DVLA_Body_Plan_Description><SMMT_Door_Plan_Code>D</SMMT_Door_Plan_Code><Engine_Size>01396</Engine_Size><DVLA_Body_Plan_Code>14</DVLA_Body_Plan_Code><Make_Code>B1</Make_Code><fuel_code>1</fuel_code><SMMT_Door_Plan_Description>5 Door Hatchback</SMMT_Door_Plan_Description><Colour_Code>J</Colour_Code><Door_Plan>5 Door Hatchback</Door_Plan><Colour>BLUE</Colour><Model_Code>591</Model_Code><transmission_code>B</transmission_code><Vin>yyyyyy6</Vin></Basic><FirstReg><Date>10/09/03</Date><vin_vrm_indicator>3</vin_vrm_indicator></FirstReg><Extended><asset_ref_nr>082250317</asset_ref_nr><smmt_make>A0</smmt_make><smmt_make_desc>Rover</smmt_make_desc><smmt_model>JA</smmt_model><smmt_model_desc>25</smmt_model_desc><smmt_trim>BE</smmt_trim><smmt_market_sector>AA</smmt_market_sector><import_marker_ni>N</import_marker_ni><import_date_ni></import_date_ni><import_vrm_ni></import_vrm_ni><co2_rating>164</co2_rating><maximum_technical_mass>00000</maximum_technical_mass><power_weight_ratio>0.00</power_weight_ratio><maximum_net_power>000</maximum_net_power><maximum_trailer_braked>00000</maximum_trailer_braked><maximum_trailer_unbraked>00000</maximum_trailer_unbraked><sound_stationary>000</sound_stationary><sound_engine>00000</sound_engine><sound_drive_by>00</sound_drive_by><seat_capacity>005</seat_capacity><mass_in_service>000001140</mass_in_service></Extended><Additional><Prev_Colour></Prev_Colour><Wheelplan>2 Axle Rigid Body</Wheelplan><Wheelplan_code>C</Wheelplan_code><Mfr_Year>2003</Mfr_Year><Import_Flag>No</Import_Flag><original_colour_code></original_colour_code><Export_Date></Export_Date><Data_Source></Data_Source><number_of_previous_colours>00</number_of_previous_colours><last_previous_colour_code></last_previous_colour_code><Weight>1500</Weight><original_colour_desc></original_colour_desc><Prev_Colour_Code></Prev_Colour_Code><Scrap_Date></Scrap_Date><last_previous_colour_code_desc></last_previous_colour_code_desc><Prev_Colour_Date> </Prev_Colour_Date></Additional><Keeper><Keepers>002</Keepers><previous_keeper_disposal_date>29/08/2008</previous_keeper_disposal_date><previous_keeper_acquisition_date>05/04/2004</previous_keeper_acquisition_date><Kpr_Change>11/09/2008</Kpr_Change></Keeper><KtypeData><Status>1</Status><Ktype><KtypeNr>14631</KtypeNr><MatchLevel>7.53</MatchLevel><EngineDetails><EngineCode>14 K4F</EngineCode></EngineDetails></Ktype></KtypeData><Summary><Veh_Regd>Recorded</Veh_Regd><Session>09040209551638</Session></Summary><Misc_Data><Guarantee_Level></Guarantee_Level><Special_Scheme></Special_Scheme><Date>Thu Apr 2 2009  09:55:51</Date></Misc_Data></HPICheck_Query>
 
I just need to get the KtypeNr!

Many thanks..
 
Code:
$p = xml_parser_create();
xml_parse_into_struct($p, $xml, $vals, $index);
xml_parser_free($p);
$desiredOutput = array('KTYPENR'); //add the things you want to retrieve here
foreach ($desiredOutput as $o){
	if (isset($index[$o])){
		$key = $index[$o][0];
		$output[$o] = trim( $vals[$key]['value'] );
	}
}
echo "<pre>" . print_r($output, true) . "</pre>";
 
HI, i get an error with the following line...

echo "<pre>" . print_r($output, true) . "</pre>";

Notice: Undefined variable: output


Regards...

Brian
 
then $output is not set. which means that the KYTPENR is not being found in the xml output.

to avoid the error add this line
Code:
$output = array();
just before the foreach line.

however that will not magically create the variable.

given the input that you have provided, the code returns the correct result on my system.
 
Hmmmm, i have aded the extra code, nut i just get...

Code:
Array
(
)

Displayed on the screen now, tried changing KtypeNr to Engine_Size and Make, etc.. but it is always the same.

Really comfused now, totally new to xml???

Any other ideas??

Kindest regards,

Brian
 
have you used the code precisely as I posted? even the case is important.

 
Hi, here is my entire code... (have changed username / password etc..)

Code:
<?php
$xml = simplexml_load_file("[URL unfurl="true"]http://www.hpixml.com/servlet/HpiGate1_0?efxid=2345678&password=ertyp&initials=jgg&function=SEARCH&vrm=x678mdf&XML=YES&product=KT001");[/URL]
$p = xml_parser_create();
xml_parse_into_struct($p, $xml, $vals, $index);
xml_parser_free($p);
$output = array();
$desiredOutput = array('KTYPENR'); //add the things you want to retrieve here
foreach ($desiredOutput as $o){
    if (isset($index[$o])){
        $key = $index[$o][0];
        $output[$o] = trim( $vals[$key]['value'] );
    }
}
echo "<pre>" . print_r($output, true) . "</pre>";
?>

[code]

and all i get is...

[code]
Array
(
)
 
you are loading the xml incorrectly for structural parsing. your method requires an alternative syntax.

this will fix it

Code:
$xml = file_get_contents("[URL unfurl="true"]http://www.hpixml.com/servlet/HpiGate1_0?efxid=2345678&password=ertyp&initials=jgg&function=SEARCH&vrm=x678mdf&XML=YES&product=KT001");[/URL]
$p = xml_parser_create();
xml_parse_into_struct($p, $xml, $vals, $index);
xml_parser_free($p);
$output = array();
$desiredOutput = array('KTYPENR'); //add the things you want to retrieve here
foreach ($desiredOutput as $o){
    if (isset($index[$o])){
        $key = $index[$o][0];
        $output[$o] = trim( $vals[$key]['value'] );
    }
}
if (count($output) > 0){
	echo "<pre>" . print_r($output, true) . "</pre>";
} else {
	echo "<pre>". print_r($vals, true) ."</pre>";
}

however with this code i receive an error set back from the remote server. i do not have the code API to decode the errors. however the process works, nevertheless.
 
Super, this works!!!! Will try to set up a session now to hold the KTypeNr!!

Many, many, thanks...!!!

Brian
 
Hi again! rom the returned results, how can i set a variable called KtypeNr and Make and set it to the values?

ie..

$KtypeNr = 14631
$Make = Rover

Code:
Array
(
    [KTYPENR] => 14631
    [MAKE] => ROVER
)

Many thanks!

Brian
 
the variables are already there.

Code:
$output['KYTEPNR'];
$output['MAKE'];
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top