PHP - Simplexml Question
Hello, I am sorry for this question in advance. I will try to explain it as detailed but, as short as possible so bare with me. I have a script that I did that parses an XML file and outputs the info in a table. The tables are created with each entry in XML file. Everything works great and as designed except for when there is no data. I know why it is doing this, I am just not sure how to approach fixing this. So here is what the data looks like where there is nothing and what the table shows. I am posting a screenshot of the XML file as I am not sure it will be empty if I post the link.
Similar TutorialsI am trying to sort these fields alphabetically by $name - $documents have run past multiple sort methods but none seem to work. I was hoping someone here knew an easy method to do this xml data: <database> <name>Test</name> <documents>0</documents> <sections>0</sections> </database> <database> <name>Test2</name> <documents>100</documents> <sections>0</sections> </database> current code: <?php $request_url = "http://10.100.100.100:9000/a=getstatus"; $xml = simplexml_load_file($request_url) or die("feed not loading"); echo "<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">\n"; echo " <tr>\n"; echo " <td>Thor Databases</td>\n"; echo " <td>Count\n"; echo $xml->responsedata->databases->num_databases; echo " </td>\n"; echo " </tr>\n"; foreach ($xml->responsedata->databases->database as $db) { echo"<tr><td>",$db->name,"</td><td>",$db->documents,"</td></tr>\n"; } echo "</table>\n"; ?> Thanks, E So I'm getting a "Notice: Trying to get property of non-object in" error when I'm trying to pull data from a xml. I have a complete xml that has all of the potential node that it could ever have and it loads up fine -no errors, but when I load a different xml that doesn't have all of the possible nodes it returns this error several times here is a sample of my code: $source = 'TestFile.xml'; $xml = new SimpleXMLElement($source,null,true); $result = mysql_query("SELECT * FROM tblvalues") or die(mysql_error()); //Return the table row by row while($row = mysql_fetch_array($result)) { $curblk = substr($row['fldelement'],0,3); switch ($row['fldelement']){ case "E06_04": case "E06_05": case "E06_07": case "E06_08": $cursub = $curblk."_04_0"; $xmlVal = $xml->Header->Record->$curblk->$cursub->$row['fldelement']; //grab value from xml break; ... ... ... // the cases go on for a while... ... case "E07_05": case "E07_06": case "E07_07": case "E07_08": $cursub = $curblk."_03_0"; $cursub2 = $curblk."_05_0"; $xmlVal = $xml->Header->Record->$curblk->$cursub->$cursub2->$row['fldelement']; //this is the line that the error points to break; ... ... ... And here is the sample of the xml that returns the error: Code: [Select] <E07> <E07_01>-20</E07_01> <E07_02>0</E07_02> <E07_15>-25</E07_15> <E07_16>-25</E07_16> <E07_17>-25</E07_17> <E07_18_0> <E07_18_01> <E07_18>-20</E07_18> <E07_19>-20</E07_19> <E07_20>-20</E07_20> </E07_18_01> .... .... .... The obvious problem (to me) is that my code is trying to return a value from a nonexistent xml node, for example: $xmlVal = $xml->Header->Record->$curblk->$cursub->$cursub2->$row['fldelement']; is looking for: $xmlVal = $xml->Header->Record->E07->E07_03_0->E07_05_0->E07_05 Ok, I get that, so how do I rewrite this so it's not blowing up on something so simple? Quick notes: -This same code works for a more complete xml -Rewriting the xmls is not an option as I have no control over those Edit: Almost forgot, thanks! Hi, I'm new to php and coding in general. I'm trying to parse xml from a remote device and access specific value data. Here is the xml: <?xml version="1.0" encoding="ISO-8859-1" ?> - <Device id="S10011" hb="1935"> <Group id="1" /> <Group id="2" /> <Group id="3" /> <Group id="4" /> <Group id="5" /> <Group id="6" /> <Group id="7" /> <Group id="8" /> - <Group id="9"> - <Probe id="99"> <Value>1.0</Value> </Probe> - <Probe id="1"> <Value>86.4</Value> </Probe> - <Probe id="2"> <Value>45.7</Value> </Probe> - <Probe id="3"> <Value>2.9</Value> </Probe> - <Probe id="4"> <Value>1.0</Value> </Probe> </Group> </Device> ----------------------- Here is my php code to read in the xml: <?php // Establish a port 80 connection $http = fsockopen("192.168.2.106",80); // Send a request to the server $req = "GET /xmldata HTTP/1.0\r\n"; $req .= "Host: 192.168.2.106\r\n"; $req .= "Connection: Close\r\n\r\n"; fputs($http, $req); // Output the request results while(!feof($http)) { $data .= fgets($http, 1024); } // Close the connection fclose($http); $xml = simplexml_load_string($data); print_r ($xml); ?> This yields the following data: SimpleXMLElement Object ( [@attributes] => Array ( [id] => S10011 [hb] => 117546 ) [Group] => Array ( => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 1 ) => ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 2 ) => ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 3 ) => ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 4 ) => ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 5 ) => ) [5] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 6 ) => ) [6] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 7 ) => ) [7] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 8 ) => ) [8] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 9 ) [Probe] => Array ( => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 99 ) [Value] => 1.0 ) [1] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 1 ) [Value] => 84.2 ) [2] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 2 ) [Value] => 44.1 ) [3] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 3 ) [Value] => 4.8 ) [4] => SimpleXMLElement Object ( [@attributes] => Array ( [id] => 4 ) [Value] => 1.0 ) ) ) ) ) I would like to display group 9 probe 1 value for example and I cannot get it to work. Any tips? so the code is <?php $xml1 = " <outer> <xml> <more_info> <user> <id>200</id> <name>CLUEL3SS</name> </user> <user> <id>201</id> <name>CLUEL3SS2</name> </user> </more_info> </xml> </outer> "; $cwb = simplexml_load_string($xml1); foreach($cwb->xml->more_info->user as $stats) { echo $stats->id."\n";} ?> output is Code: [Select] 200 201 Now, how can I echo the name under <id>201</id> since there is more than one? echo $stats->id."\n"; That echos both of the "ID" values, now how can I get it to only echo the second id 201 and the second name? Thanks Ok so I have a url that is an XML doc, it says at the top "This XML file does not appear to have any style information associated with it. The document tree is shown below." and it has info like this Code: [Select] <outer> <xml> <viewer> <user> <id>1245789</id> <name>CLueless</user> <business>none</business> </user> </viewer> </xml> </outer> How would I load the link and then assign everything to a variable like id, name and business I usually use something like this but Im trying to get learn simple xml $info = file_get_contents('url'); $id = explode('<id>', $info); $id = explode('</', $id[1]); $name = explode('<name>', $info); $name = explode('</', $name[1]); $biz = explode('<business>', $info); $biz = explode('</', $biz); Thanks in advance for your help. I have the following code Code: [Select] function traverseXMLNodes($xml) { $xml = stripslashes($xml); $xml =simplexml_load_string("<div>{$xml}</div>");//This the line that makes errors its line 70 echo 'Displaying contents of XML file...<br />'; print_r($xml); } Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : xmlParseCharRef: invalid xmlChar value 0 in /home/wwwsend/public_html/postSample_Reply3.php on line 70 (Where i have written This the line that makes errors) Warning: simplexml_load_string() [function.simplexml-load-string]: yid><eventid>60387073</eventid><numfrom>27826641429</numfrom><receiveddata>� in /home/wwwsend/public_html/postSample_Reply3.php on line 70 Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /home/wwwsend/public_html/postSample_Reply3.php on line 70 Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : xmlParseCharRef: invalid xmlChar value 0 in /home/wwwsend/public_html/postSample_Reply3.php on line 70 Warning: simplexml_load_string() [function.simplexml-load-string]: ventid>60387073</eventid><numfrom>27826641429</numfrom><receiveddata>�O� in /home/wwwsend/public_html/postSample_Reply3.php on line 70 I'm pretty new to php. But the below script should get news articles from google news rss. It is failing to load the simplexml and returns false. Any idea why? Code: [Select] $url = "http://news.google.com/news?geo=90210"; if ($xml = @simplexml_load_file($url)) { for ($i=0; $i<4; $i++) { $item= $xml->channel->item[$i]; $link= '<a href = "'.(string) $item->link.'", target= "_blank">'.(string) substr($item->title, 0, 50).'...</a><br />'; $news[]= $link; } } I'm having a problem trying to understand how to grab the following values, <times> <time type="join">1293756060</time> <time type="leave">1293756420</time> </times> Ive read and tried everything I can find for a couple days now and cant get anything to grab both separate times foreach ($xml->times->time as $times){ $timein{$num} = $times; //this grabs leave time, by accident im sure lol $timeout{$num} = ???????; //dont know how to separate them by join/leave. } any help would be great. I get strings via simplexml with this code $xml = simplexml_load_file("test.xml"); foreach ($xml->title->case as $value){ $param1 = $value->param1; $param2 = $value->param2; Now I want to randomize the xml items (not in their original order); but I cannot use shuffle($value); because it does not consider $value as an array. How can I make a random order? Working with a now playing module for some music. My music player outputs this kind of XML (WHEN THE SONG IS PLAYING): <?xml version="1.0" encoding="utf-8" ?> - <Playing station="Station"> - <item type="MUS"> <Artist>Beatles</Artist> <SongTitle>Get Back</SongTitle> </item> </Playing> My music player outputs this kind of XML (WHEN THE SONG IS NOT PLAYING): <?xml version="1.0" encoding="utf-8" ?> - <Playing station="Station"> - <item type="END"> <Artist>MORE MUSIC SOON</Artist> <SongTitle /> </item> </Playing> Here's my PHP: Code: [Select] <?php $playing = simplexml_load_file("../playlist/nowplaying.xml"); foreach ($playing->item as $item) { printf("Now playing: %s\n", $item->SongTitle); printf("by %s\n", $item->Artist); } ?> I want to make my php document check the item TYPE. (item type="x"). If x equals "MUS", display the PHP like above. But if x displays "END", I want it to display something like "More music coming up". Right now, it displays "MORE MUSIC SOON by " I've attempted if statements to no avail, mainly because I'm not super familiar with them in PHP. Ideas? Hey there, I'm having a issue when I edit the XML file from a string here. Now the SimpleXML functions edit the nodes of the XML file perfectly and everything is done the way I want but upon returning the file to a string it keeps putting a XML content type at the top of the file, E.G: Before XML File Is Edited: Code: [Select] <settings> <!-- Port the server will listen on --> <port>7781</port> <!-- Maximum number of players the server will support (Max 32) --> <maxplayers>10</maxplayers> <!-- Maximum number of vehicles the server will support (Max 140) --> <maxvehicles>100</maxvehicles> <!-- Password clients will have to enter to connect --> <!-- password>None</password --> <!-- Add the server to the master list --> <listed>true</listed> <!-- The hostname players will see --> <hostname>IV:MP Server</hostname> <!-- The address the server will bind to --> <!-- hostaddress>127.0.0.1</hostaddress --> <!-- Toggles frequently called events which has impact on CPU usage --> <frequentevents>false</frequentevents> <!-- The scripts the server will load and run --> <script>cp.nut</script> <script>whisper.nut</script> <script>namecheck.nut</script> <script>runcode.nut</script> <!-- The modules the server will load and run --> <!-- For windows: --> <!-- module>Sample.dll</module --> <!-- For linux: --> <!-- module>Sample.so</module --> </settings> After XML File Is Edited Code: [Select] <?xml version=1.0?> <settings> <!-- Port the server will listen on --> <port>7781</port> <!-- Maximum number of players the server will support (Max 32) --> <maxplayers>10</maxplayers> <!-- Maximum number of vehicles the server will support (Max 140) --> <maxvehicles>100</maxvehicles> <!-- Password clients will have to enter to connect --> <!-- password>None</password --> <!-- Add the server to the master list --> <listed>true</listed> <!-- The hostname players will see --> <hostname>IV:MP Server</hostname> <!-- The address the server will bind to --> <!-- hostaddress>127.0.0.1</hostaddress --> <!-- Toggles frequently called events which has impact on CPU usage --> <frequentevents>false</frequentevents> <!-- The scripts the server will load and run --> <script>cp.nut</script> <script>whisper.nut</script> <script>namecheck.nut</script> <script>runcode.nut</script> <!-- The modules the server will load and run --> <!-- For windows: --> <!-- module>Sample.dll</module --> <!-- For linux: --> <!-- module>Sample.so</module --> </settings> Notice the addition to the header of the file "<?xml version=1.0?>". This is causing issues when the XML file is read by the server. Could anybody help me stop the SimpleXML editor from placing this in the header of the file? Thanks. Hi I want the icon of a digg user $apicall = 'http://services.digg.com/2.0/user.getInfo?usernames='.$username.'&type=xml'; $result = simplexml_load_file($apicall); print_r($result);() With that code I'll get this: Quote SimpleXMLElement Object ( [count] => 1 [users] => SimpleXMLElement Object ( [Ericquits] => SimpleXMLElement Object ( [username] => Ericquits [about] => SimpleXMLElement Object ( ) [user_id] => 20111010190724:bbd2c60f-17a6-4dc1-8a03-6fd96322752e [name] => Eric Quit [icons] => SimpleXMLElement Object ( [item] => Array ( => http://cdn3.diggstatic.com/user/20111010190724:bbd2c60f-17a6-4dc1-8a03-6fd96322752e/c.4164547322.png [1] => http://cdn1.diggstatic.com/user/20111010190724:bbd2c60f-17a6-4dc1-8a03-6fd96322752e/h.4164547322.png [2] => http://cdn3.diggstatic.com/user/20111010190724:bbd2c60f-17a6-4dc1-8a03-6fd96322752e/m.4164547322.png [3] => http://cdn3.diggstatic.com/user/20111010190724:bbd2c60f-17a6-4dc1-8a03-6fd96322752e/l.4164547322.png [4] => http://cdn1.diggstatic.com/user/20111010190724:bbd2c60f-17a6-4dc1-8a03-6fd96322752e/p.4164547322.png [5] => http://cdn3.diggstatic.com/user/20111010190724:bbd2c60f-17a6-4dc1-8a03-6fd96322752e/s.4164547322.png [6] => http://cdn3.diggstatic.com/user/20111010190724:bbd2c60f-17a6-4dc1-8a03-6fd96322752e/r.4164547322.png ) ) [gender] => SimpleXMLElement Object ( ) [diggs] => 12 [comments] => 1 [followers] => 373 [location] => SimpleXMLElement Object ( ) [following] => 235 [submissions] => 9 [icon] => http://cdn3.diggstatic.com/user/20111010190724:bbd2c60f-17a6-4dc1-8a03-6fd96322752e/p.4164547322.png ) ) [title] => Info for users Ericquits [timestamp] => 1320350425 [uri] => http://services.digg.com/2.0/user.getInfo?usernames=Ericquits&type=json [cursor] => SimpleXMLElement Object ( ) [version] => 2.0 [authorized] => 0 [data] => users [method] => user.getInfo [user] => None So I want the icon the profile image of the user and I make this: print (string)$result->users->Ericquits->icon;() This works, but my question is if there is a solution to get the icon without Ericquits the username? Because if write it little I don't get the icon... Hi, I don't know why the foreach loop doesn't output the text node content of <toFirstName> and <toLastName>? please see email.xml file below: Code: [Select] <?xml version="1.0" encoding="ISO-8859-1"?> <email> <message> <to> <toFirstName>Tove</toFirstName> <toLastName toType="common" style="swag">Smith</toLastName> </to> <from> <fromFirstName>Jani</fromFirstName> <fromLastName fromType="unique">Dravison</fromLastName> </from> <heading>Reminder</heading> <body> <prologue>Tis the night before Xmas...</prologue> <paragraph1>Don't forget me this weekend!</paragraph1> <paragraph2>Jump the gun!</paragraph2> <epilogue>The end of the world.</epilogue> </body> </message> </email> Please see script below: ================= Code: [Select] <?php $simpleXMLObj=simplexml_load_file("email.xml"); foreach($simpleXMLObj->message[0]->to[0] AS $curDOM) { print $curDOM->toFirstName->getName."<br />".$curDOM->toLastName->getName."<br />"; ?> Please help me out, I would really appreciate it! Hello and thanks in advance for any help. Overview: Im tyring to pull data from a XML api using simpleXML. I have ran into a problem with special characters and entities that simpleXML does not accept. IE " " Ive tried all the solutions i could find to no avail. SimpleXML gives me this error. parser error : Entity 'nbsp' not defined in Here is my code. Code: [Select] $feed = simplexml_load_file('URL TO API FEED'); $feed = html_entity_decode($feed); $feed = str_ireplace(array('<','>','&','\'','"'),array('<','>','&',''','"'),$feed); echo 'Game Title: ' .$feed->game. '</br>'; echo 'Ponts Earned: ' .$feed->gamerscore. '</br>'; echo 'Total Achievements: ' .$feed->totalachievements. '</br>'; foreach($feed->achievements->achievement as $ach) { $output = htmlentities($feed->title, ENT_QUOTES, "UTF-8"); echo $output; if( !empty($ach->unlockedartwork)){ echo '<img src=' .$ach->unlockedartwork. '></img></br>'; }else { echo '<img src=' .$ach->artwork. '></img></br>'; } } Here is the code im trying to retrieve. Code: [Select] <achievement id="40"> <title>Have Gun Will Travel </title> <artwork>http://</artwork> <gamerscore>20</gamerscore> <unlocked>true</unlocked> <unlockdate>7/4/2010</unlockdate> </achievement> Greetings, I am trying to write XML using SimpleXML for a web service call. I was having success until the XML got a little more complicated. Here is the XML format where I am running into problems: Code: [Select] <Agent> <Person Last='Smith' First='John'> <Addresses /> <PhoneNumbers> <Phone Type='1' Number='888-555-1212'> </PhoneNumbers> </Person> </Agent> Here is my php: Code: [Select] $xmlOutput = new SimpleXMLElement('<?xml version="1.0"?><ReportRequest> </ReportRequest>'); $xmlOutput->addAttribute('CID','9200'); $xmlOutput->addAttribute('Diagram','1'); $xmlOutput->addAttribute('DueDate','2011-11-15'); $xmlOutput->addAttribute('NumPhotos','6'); $xmlOutput->addAttribute('InspectAfter',''); $xmlOutput->addAttribute('PolicyNumber','JTC0004425'); $reportType = $xmlOutput->addChild('ReportType'); $reportType->addAttribute('CPType','Commercial'); $reportType->addAttribute('SectionIDs',''); $reportType->addAttribute('Description',''); $reportType->addAttribute('ReportTypeID','123'); $locations = $xmlOutput->addChild('Locations')->addChild('Addresses')->addChild('Address'); $locations->addAttribute('Zip','91216'); $locations->addAttribute('City','Chatsworth'); $locations->addAttribute('Line1','123 Main St'); $locations->addAttribute('Line2','Suite 201'); $locations->addAttribute('State','CA'); $locations->addAttribute('Latitude',''); $locations->addAttribute('Longitude',''); $agent = $xmlOutput->addChild('Agent')->addChild('Person')->addChild('Addresses')->addChild('PhoneNumbers')->addChild('Phone'); $agent->addAttribute('Last','Smith'); $agent->addAttribute('Email',''); $agent->addAttribute('First','John'); $agent->addAttribute('Title',''); $agent->addAttribute('Type','1'); $agent->addAttribute('Number','888-555-1212'); $agent->addAttribute('TypeName','Office'); $agent->addAttribute('Extension',''); Header('Content-type: text/xml'); echo $xmlOutput->asXML(); Everything outputs as it should until the line that starts with $agent. I want the output to match the section above. I have tried several variations but I cannot seem to figure it out. I know the current PHP sample doesn't work. Help?? Thanks in advance, John I have limited idea about SimpleXML but not with the code below and need to edit it so the results can be parsed into a html format. The problem i am having is the XML tags are stored in an existing variable returned from a third party server so need something that can parse this xml info into a html with tags being used. Code: [Select] $xml = "<Inputs>"; $xml.= "<Authentication>"; $xml.= "<Username>$username</Username>"; $xml.= "<Password>$password</Password>"; $xml.= "<RequestType>Term</RequestType>"; $xml.= "<RequestFrom>$system_name</RequestFrom>"; $xml.= "<RequestFromCode>$system_code</RequestFromCode>"; $xml.= "</Authentication>"; $xml.= "<Life1>"; $xml.= "<DOB>$dob</DOB>"; $xml.= "<Sex>$sex</Sex>"; $xml.= "<Smoker>$smoker</Smoker>"; $xml.= "<LifeCover>$lifecover</LifeCover>"; $xml.= "<IllnessCover>N</IllnessCover>"; $xml.= "</Life1>"; $xml.= "<Life2>"; $xml.= "</Life2>"; $xml.= "<Plan>"; $xml.= "<Term>$term</Term>"; $xml.= "<Indexation>N</Indexation>"; $xml.= "<MortgageInterest>6</MortgageInterest>"; $xml.= "<Frequency>Monthly</Frequency>"; $xml.= "<QuoteLifeOnly>Y</QuoteLifeOnly>"; $xml.= "<QuoteLifeAccelerated>$accelerated</QuoteLifeAccelerated>"; $xml.= "<QuoteLifeIllness>N</QuoteLifeIllness>"; $xml.= "<QuoteIllnessOnly>N</QuoteIllnessOnly>"; $xml.= "</Plan>"; $xml.= "</Inputs>"; $url = 'URL NORMALLY HERE'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "xml=".urlencode($xml)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $xml_result=curl_exec($ch); curl_close($ch); print("[$xml_result]"); /* simple xml */ $simplexml = new SimpleXMLElement($xml_result); $Name = $simplexml->Name; echo $Name; /* end */ $data = XML_unserialize($xml_result); $xml_result contains... (with usernames/passwords removed) Code: [Select] <Result> <Errors></Errors> <Inputs><Authentication><Username>####</Username> <Password>####</Password><RequestType>Term</RequestType><RequestFrom>####</RequestFrom><RequestFromCode>####</RequestFromCode></Authentication><Life1><DOB>01/01/1969</DOB><Sex>Male</Sex><Smoker>Non-Smoker</Smoker><LifeCover>100,000</LifeCover><IllnessCover>N</IllnessCover></Life1><Life2></Life2><Plan><Term>10</Term><Indexation>N</Indexation><MortgageInterest>6</MortgageInterest><Frequency>Monthly</Frequency><QuoteLifeOnly>Y</QuoteLifeOnly><QuoteLifeAccelerated>Non-Smoker</QuoteLifeAccelerated><QuoteLifeIllness>N</QuoteLifeIllness><QuoteIllnessOnly>N</QuoteIllnessOnly></Plan></Inputs><Outputs> <Summary> <Life1>Male, 40 years 8 months (01/01/1969), Non-Smoker, life cover 100,000</Life1> <Life2></Life2> <Plan>10 year term, mortgage interest 6.00%, benefits and premiums not increasing.<p>1% levy included.</p></Plan> </Summary> <Quotes> <Type> <Desc>Life Cover Only</Desc> <Company> <Name key="1">Caledonian Life</Name> <PricePledge>False</PricePledge> <Underwriting1></Underwriting1> <SLevel key="2">14.50</SLevel> <SConvertible key="2">15.46</SConvertible> <SMortgage key="2">12.12</SMortgage> </Company> <Company> <Name key="2">Canada Life</Name> <PricePledge>False</PricePledge> <Underwriting1></Underwriting1> <SLevel key="2">15.15</SLevel> <SConvertible key="2">15.91</SConvertible> <SMortgage key="2">13.13</SMortgage> </Company> </Type> </Quotes> </Outputs> </Result> Any advice would be much appreciated I am trying to retrieve an attribute from a node and I keep getting the error: Warning: main() [function.main]: Node no longer exists in /Users/dmonsewicz/Projects/noosemonsewicz/api_stuff/index.php on line 70 PHP Code Code: [Select] $xml = new SimpleXMLElement($result); $arr = $xml->tickets->attributes(); echo $arr['count']; XML Code: [Select] <tickets count="0" type="array"></tickets> Any ideas on what I may be doing wrong? Hello, I'm trying to read the data of a xml file with the help of simplexml. I'm having trouble reading subchilds. For example im trying to read the following xml: <root> <child> <subchild> <dataineed/> <dataineed/> <dtaineed/> <subchild> </child> </root> I'm using the following code: <?php $oLinkjes = new SimpleXMLElement('http://feedlink.php', 0, TRUE); $countcat = count($oLinkjes->subchild); echo $countcat; ?> It echo's the the result '0' which means that it does not successfully reads the subchild. Because of that i can't get the data i want. When i change subchild to child is does echo '1'. Anyone knows what I'm doing wrong here? I'm new to xml so there might be a easy fix to this. Hi I am trying to use SimpleXML to populate some form fields from an XML file This is the SimpleXML code that I am using Code: [Select] <?php $vrm=strtoupper($_POST['veh_reg']); $file="https://www.cdlvis.com/lookup/getxml?username=username&mode=test&key=key&vrm=".$vrm.""; $dom=new DOMdocument(); $dom->load($file); $xml=simplexml_import_dom($dom); var_dump($xml); ?> The code for the display of the fields is: Code: [Select] <form name="vehicle_details" method="post" action="add_vehicle.php"> <table> <tr> <td>Registration Number:</td><td><input name="reg_num" type="text" value="<?php echo $xml->result[0]->vrm;?>" readonly="true" /></td></tr> <tr> <td>Make:</td><td><input name="make" type="text" value="<?php echo $xml->result[0]->make;?>" readonly="true" /></td></tr> <tr> <td>Model:</td><td><input name="model" type="text" value="<?php echo $xml->result[0]->model;?>" readonly="true" /></td></tr> <tr> <td>Date of Manufactu </td><td><input name="date_man" type="text" value="<?php echo $xml->result[0]->date_manufactured;?>" readonly="true" /></td></tr> <tr> <td>Date of First Registration:</td><td><input name="date_reg" type="text" value="<?php echo $xml->result[0]->first_registered;?>" readonly="true" /></td></tr> <tr> <td>Colour:</td><td><input name="colour" type="text" value="<?php echo $xml->result[0]->colour;?>" readonly="true" /></td></tr> <tr> <td>Body Style:</td><td><input name="body" type="text" value="<?php echo $xml->result[0]->body;?>" readonly="true" /></td></tr> <tr> <td>Number of Doors:</td><td><input name="doors" type="text" value="<?php echo $xml->result[0]->doors;?>" readonly="true" /></td></tr> <tr> <td>Engine Size:</td><td><input name="engine_size" type="text" value="<?php echo $xml->result[0]->engine_size;?>" readonly="true" /></td></tr> <tr> <td>Fuel Type:</td><td><input name="fuel_type" type="text" value="<?php echo $xml->result[0]->fuel;?>" readonly="true" /></td></tr> <tr> <td>Gearbox Type:</td><td><input name="gearbox" type="text" value="<?php echo $xml->result[0]->gearbox_type;?>" readonly="true" /></td></tr> <tr> <td>Previous Keepers:</td><td><input name="keepers" type="text" value="<?php echo $xml->result[0]->previous_keepers;?>" readonly="true" /></td></tr> <tr> <td>BHP:</td><td><input name="bhp" type="text" value="<?php echo $xml->result[0]->smmt_power_bhp;?>" readonly="true" /></td></tr> <tr> <td>Emissions:</td><td><input name="co2" type="text" value="<?php echo $xml->result[0]->smmt_co2;?>" readonly="true" /></td></tr> <tr> <td><input name="try_again" type="button" value="Try Again" /></td><td><input name="submit" type="submit" value="Next Stage" /></td></tr> </table> </form> In each of the fields on the form when I run the code is the following error Notice: Trying to get property of non-object in I have also done a var_dump of the xml and I get the following Code: [Select] object(SimpleXMLElement)#2 (15) { ["@attributes"]=> array(4) { ["id"]=> string(6) "344571" ["generated"]=> string(10) "1300307651" ["mode"]=> string(4) "test" ["account_id"]=> string(3) "165" } ["vrm"]=> string(7) "DC70XSC" ["make"]=> string(7) "RENAULT" ["model"]=> string(23) "SCENIC EXPRESSION 16V A" ["date_manufactured"]=> string(10) "2004-02-20" ["first_registered"]=> string(10) "2004-02-20" ["colour"]=> string(5) "GREEN" ["body"]=> string(3) "MPV" ["doors"]=> string(7) "5 DOORS" ["engine_size"]=> string(4) "1598" ["fuel"]=> string(6) "PETROL" ["gearbox_type"]=> string(19) "TIPTRONIC AUTOMATIC" ["previous_keepers"]=> string(1) "1" ["smmt_power_bhp"]=> string(5) "115.1" ["smmt_co2"]=> object(SimpleXMLElement)#3 (0) { } } What have I done wrong, any help will be much appreciated. |