PHP - Parsing Feedburner Rss Feed With Simplexml
Hi,
I've run into a problem, or rather users of the ap I'm developing are likely to run into a problem. I'm using simplexml with curl to parse RSS feeds. Mostly that works just fine. The trouble I've run into is that if a user is using feedburner. If they enter the feedburner url (http://feeds2.feedburner.com/blah) when asked for the feed they want parsed it is not a problem. If however they give the original feed url (http://mysite/feed) then the parser cannot load the feed. The relevant code is: Code: [Select] $settings['feed-url']='http://mysite/feed'; //Fetch the RSS feed $ch = curl_init( $settings['feed-url'] ); if(!($ch)) echo "Could not initialise feed"; curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); if(!$feed = simplexml_load_string ( curl_exec($ch) )) echo "Could not load feed ".$settings ['feed-url']; curl_close($ch); That will result in the message displayed being "Could not load feed http://mysite/feed". If I switched the feed to be http://feeds2.feedburner.com/blah then it would work perfectly. I could tell people to just use their feedburner address, but it would be better if they could put in either. My browser can handle it, so my ap should be able to handle it too. Any ideas? I can't find this problem mentioned anywhere. Similar TutorialsI 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 hi. Basically, I am trying to set up a random bible verse script. I found an rss/xml feed he http://www.mybiblescripture.com/rss/bible.php?fmt=daily&trans=KJV Using the following code, I am attempting to parse the feed in to an array: Code: [Select] <?php function fetchXML($url) { //initialize library $ch = curl_init(); //used to make us look like a browser $useragent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"; //set the url curl_setopt ($ch, CURLOPT_URL, $url); //set that I want to wait for a response curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); //make us look like a web browser curl_setopt ($ch, CURLOPT_USERAGENT, $useragent); //get data $data = curl_exec($ch); //clean up curl_close($ch); //return xml data return $data; } define("USE_CURL", true); $url = "http://www.mybiblescripture.com/rss/bible.php?fmt=daily&trans=KJV"; //get xml doc with info $data = fetchXML($url); //create a SimpleXML object to parse the xml $char_xml = new SimpleXmlElement($data); echo print_r($char_xml); ?> Which gives me the following output: Code: [Select] SimpleXMLElement Object ( [@attributes] => Array ( [version] => 2.0 ) [channel] => SimpleXMLElement Object ( [title] => My Bible Scripture - Bible Verse of the Day (KJV) [link] => http://www.mybiblescripture.com/ [description] => Verse of the Day - King James Version [language] => en-us [pubDate] => SimpleXMLElement Object ( ) [generator] => CPG-Nuke Dragonfly [copyright] => My Bible Scripture [category] => Religion [image] => SimpleXMLElement Object ( [width] => 111 [height] => 40 [url] => http://www.mybiblescripture.com/images/logo.gif [title] => My Bible Scripture [link] => http://www.mybiblescripture.com/ ) [item] => Array ( [0] => SimpleXMLElement Object ( [title] => Corinthians I 10:17 [link] => http://www.mybiblescripture.com/Bible/l_op=view-verse/lid=29613/trans=KJV.html [description] => For we being many are one bread, and one body: for we are all partakers of that one bread. (KJV) [pubDate] => SimpleXMLElement Object ( ) ) [1] => SimpleXMLElement Object ( [title] => Bible Verses [link] => http://www.mybiblescripture.com [description] => Find more Bible Scripture [pubDate] => Fri, 11 Mar 2011 00:45:06 GMT ) ) ) ) 1 What I am trying to do is pull ONLY [title] => Corinthians I 10:17 and its accompanying verse [description] => For we being many are one bread, and one body: for we are all partakers of that one bread. (KJV). I am very bad at trying to read multi-dim arrays and can't for the life of me figure out how to print the aforementioned keys. Could anyone help me here? thanks 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 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? 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); Hello, Hope somebody can help me. I have an XML file that is generated by active directory that dumps everything required for a telephone directory. I currently present this using XSL but would like to move towards PHP. I have some rudimentary code and it's working fine but I'd like to be able to sort by various values, such as First Name or telephone number. My XML format looks like this: Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <telephonelist> <employee> <firstname>Jimmy</firstname> <lastname>Jimmerson</lastname> <email>jimbo@companyxyz.com</email> <extensionnum>956</extensionnum> <jobtitle>Security Officer</jobtitle> <department>Security</department> </employee> <employee> <firstname>David</firstname> <lastname>Davidson</lastname> <email>David.Davidson@companyxyz.com</email> <extensionnum>968</extensionnum> <jobtitle>Manager</jobtitle> <department>Management</department> </employee> Any my current code looks like this: Code: [Select] <? $myStaffMembers = new SimpleXMLElement("includes/telephonelist.xml", null, true); echo <<<EOF <table width="95%" border="0"> <tr> <th><b>First Name</b></th> <th><b>Last Name</b></th> <th><b>Telephone Number</b></th> <th><b>Position</b></th> </tr> EOF; foreach($myStaffMembers as $myStaffMember) { echo " <tr> <td>{$myStaffMember->firstname}</td> <td>{$myStaffMember->lastname}</td> <td>{$myStaffMember->extensionnum}</td> <td>{$myStaffMember->jobtitle}</td> </tr>"; } ?> Appreciate any help anybody could give. Thanks, LJ 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. 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? 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> 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! 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... 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; } } 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 guys! I'm trying to parse an RSS feed using SimpleXML, but I'm having trouble lol Here's my code: $feed = file_get_contents("http://engadget.com/rss.xml"); $xml = new SimpleXMLElement($feed); echo $xml->rss->channel->item[0]->title; I'm expecting it to echo the title of the first item in the RSS feed, but when I run it, I just see a blank page. Tell me what I'm doing wrong! 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. 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'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. Hey guys I have the following code: Code: [Select] $xml = new SimpleXMLElement( 'http://steamcommunity.com/profiles/76561197963859775?xml=1' , NULL, TRUE ); print_r($xml);The problem here is that it doesnt echo everything correctly... It doesn't show avatarFull for me Code: [Select] impleXMLElement Object ( [steamID64] => 76561197961308838 [steamID] => SimpleXMLElement Object ( ) [onlineState] => in-game [stateMessage] => SimpleXMLElement Object ( ) [privacyState] => public [visibilityState] => 3 [avatarIcon] => SimpleXMLElement Object ( ) [avatarMedium] => SimpleXMLElement Object ( ) [avatarFull] => SimpleXMLElement Object ( ) That's what it shows, the avatarFull and a couple others are empty. How do I fix this? Thank you 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? |