kawaii1001 Posted August 25, 2013 Share Posted August 25, 2013 (edited) I am very basic with php and am needed to parse an xml file. I have completed to where it is pulling some parts, but isn't pulling the children, and I am uncertain how to grab those. This is what I have: <?php $preowned = simplexml_load_file('File.xml'); foreach ($preowned as $preownedinfo): $ADID=$preownedinfo->ADID; $CompanyID=$preownedinfo->CompanyID; $Category=$preownedinfo->Category; $StockNumber=$preownedinfo->StockNumber; $Year=$preownedinfo->Yrs; $Make=$preownedinfo->Make; $Model=$preownedinfo->Model; $Trim=$preownedinfo->Trim; $Odometer=$preownedinfo->Odometer; $ExteriorColor=$preownedinfo->ExteriorColor; $InteriorColor=$preownedinfo->InteriorColor; $Engine=$preownedinfo->Engine; $Transmission=$preownedinfo->Transmission; $Doors=$preownedinfo->Doors; $Price=$preownedinfo->Price; $Options=$preownedinfo->Options; $AdDescription=$preownedinfo->AdDescription; $MainPhoto=$preownedinfo->MainPhoto; $AdditionalPhoto=$preownedinfo->AdditionalPhoto; $Doors=$preownedinfo->Doors; echo $Year $Make $Doors $Model; endforeach; ?> Here is the xml: <root><AD><ADID displayName="ADID">1111</ADID><CompanyID displayName="CompanyID">0000</CompanyID><CompanyName displayName="CompanyName">Company Name</CompanyName><Category displayName="Category">Sport Utility</Category><StockNumber displayName="StockNumber">999999</StockNumber><Vin displayName="Vin">22222</Vin><Status displayName="Status">Used</Status><Yrs displayName="Year">2010</Yrs><Make displayName="Make">Lincoln</Make><Model displayName="Model">Navigator</Model><Trim displayName="Trim">Sport Utility</Trim><ExtraField displayName="ExtraField"><ContentEN><Odometer>47610</Odometer><ExteriorColor>White</ExteriorColor><InteriorColor>Black</InteriorColor><FuelType>Flexible</FuelType><Drive>AWD</Drive><Engine>V8 Flex Fuel 5.4L</Engine><Transmission>Automatic</Transmission><Doors>4</Doors></ContentEN></ExtraField><Price displayName="Price">44900.0000</Price><HidePrice displayName="HidePrice">0</HidePrice><Options displayName="Options">AM/FM Stereo, Air Conditioning</Options><AdDescription displayName="AdDescription">AC Seats,Heated Seats,Memory Seats,Wood Trim</AdDescription><FinancingIsAvailable displayName="FinancingIsAvailable">0</FinancingIsAvailable><FinancingPayment displayName="FinancingPayment" /><FinancingPaymentType displayName="FinancingPaymentType" /><FinancingNumberOfPayment displayName="FinancingNumberOfPayment" /><FinancingDownPayment displayName="FinancingDownPayment" /><FinancingSource displayName="FinancingSource" /><FinancingType displayName="FinancingType" /><FinancingOdometer displayName="FinancingOdometer" /><FinancingDescription displayName="FinancingDescription" /><ManufactureProgram displayName="ManufactureProgram" /><Warranty displayName="Warranty" /><WarrantyDescription displayName="WarrantyDescription" /><MainPhoto displayName="MainPhoto">http://www.photo.jpg</MainPhoto><AditionalPhotos displayName="AditionalPhotos"><AditionalPhoto>http://www.photo.jpg</AditionalPhoto></AditionalPhotos><ModifiedDate displayName="ModifiedDate">06/18/2013 15:17:17</ModifiedDate><CreatedDate displayName="CreatedDate">03/30/2011 21:47:53</CreatedDate></AD><AD><ADID displayName="ADID">111111</ADID></AD></root> Edited August 25, 2013 by kawaii1001 Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 25, 2013 Share Posted August 25, 2013 (edited) Debug your xml data outputs and turn on error_reporting on the top of the file: This is wrong php syntax - echo $Year $Make $Doors $Model; Use code tags in the future! Try, (uncomment my echo's) <?php error_reporting(-1); if (file_exists('File.xml')) { $preowned = simplexml_load_file('File.xml'); foreach ($preowned as $preownedinfo): $ADID=$preownedinfo->ADID; $CompanyID=$preownedinfo->CompanyID; $Category=$preownedinfo->Category; $StockNumber=$preownedinfo->StockNumber; $Year=$preownedinfo->Yrs; $Make=$preownedinfo->Make; $Model=$preownedinfo->Model; $Trim=$preownedinfo->Trim; $Odometer=$preownedinfo->Odometer; $ExteriorColor=$preownedinfo->ExteriorColor; $InteriorColor=$preownedinfo->InteriorColor; $Engine=$preownedinfo->Engine; $Transmission=$preownedinfo->Transmission; $Price=$preownedinfo->Price; $Options=$preownedinfo->Options; $AdDescription=$preownedinfo->AdDescription; $MainPhoto=$preownedinfo->MainPhoto; $AdditionalPhoto=$preownedinfo->AdditionalPhoto; $Doors=$preownedinfo->ExtraField->Doors; // echo '<pre>'.print_r($preownedinfo->ADID,true).'</pre>'; // echo '<pre>'.print_r($preownedinfo->ExtraField,true).'</pre>'; //echo '<pre>'.print_r($preownedinfo->ExtraField->ContentEN, true).'</pre>'; endforeach; } else { exit('Failed to open File.xml.'); } Edited August 25, 2013 by jazzman1 Quote Link to comment Share on other sites More sharing options...
kawaii1001 Posted August 25, 2013 Author Share Posted August 25, 2013 Apologies. I just threw that echo in, but it's more how to grab the children. For example, it will grab Make and Model, but then anything inside of the "ExtraFields", (e.g. Doors, Trim), it won't. Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted August 25, 2013 Share Posted August 25, 2013 I already told you how! Check out my echo's. Quote Link to comment Share on other sites More sharing options...
kawaii1001 Posted August 27, 2013 Author Share Posted August 27, 2013 Excellent. Thank you. Another question - How do I get the Price to show as a number value? I tried: echo '<pre>'.print_r(money_format($Price, 2));.'</pre>'; 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.