simplexml

SimpleXml class not found

After initiating a new SimpleXml object: $xml = new SimpleXML($xmlStr); PHP errors out: Fatal error: Class 'SimpleXML' not found PHP info reads: Simplexml support enabled Revision $Revision: 1.151.2.22.2.35.2.32 $ Schema support enabled What could possibly be going wrong? ...

How do I access variables with hyphenated names in Smarty?

I've got a PHP page that parses an XML file with SimpleXml, then passes that object to a Smarty template. My problem is that the XML file has hyphens in its tag names, e.g. video-player. In PHP, this is no problem, I just use $xml->{'video-player'} and everything's fine. Smarty, on the other hand, throws a fit when I try to use that synt...

Which is much faster, XMLParser or SimpleXML

What do you think guys? I currently using SimpleXML for my entire project, which have average of 250KB in memory usage w/ 500micro seconds processing per execution. I just plan to switch to XMLParser, your advice is much appreciated. Edit : The actual microtime is 0.000578 micro seconds. Im just confused in milli and micro, lol. ...

SimpleXML not pulling correct link

My code does not pull the proper link for the item. Instead it's getting the previous item's link. Any suggestions? Thanks! <?php // Load the XML data from the specified file name. // The second argument (NULL) allows us to specify additional libxml parameters, // we don't need this so we'll leave it as NULL. The third argument howe...

Add rss xmlns namespace definition to a php simplexml document?

I'm trying to create an itunes-valid podcast feed using php5's simplexml: <?php $xml_string = <<<XML <?xml version="1.0" encoding="UTF-8"?> <channel> </channel> XML; $xml_generator = new SimpleXMLElement($xml_string); $tnsoundfile = $xml_generator->addChild('title', 'Main Title'); $tnsoundfile->addChild('itun...

php: simplexml exception retry

I am querying an API using SimpleXML which will occasionally fail for reasons unknown. I would like to have the script retry up to 5 times. How can I do this? I assume it has something to do with wrapping the object in a try/catch, but I'm not very experienced with this -- have tried to read the manual on exception handling but am sti...

Write a foreach loop for array of SimpleXMLElements

Hi, I am using the XPath in PHP 5 to parse a XML document. The problem I have is writing a foreach to correctly display the following array: XML document sample value 1 value 2 $xmlfile = 'link_to_file.xml'; $xmlRaw = file_get_contents($xmlfile); ...

PHP: SimpleXML and Arrays

When I run this code: foreach($xml->movie as $movie) { if(isset($movie->photos)) { foreach ($movie->photos as $photo) { echo $photo."&nbsp;"; } echo "<hr/>"; } } I get nice output of the actual data, e.g. a row looks like 06397001.jpg 06397002.jpg 06397003.jpg 06397004.jpg 06397005.jpg But when I throw it in an array, it includes a...

Extracting Certain XML Elements with PHP SimpleXML

I am having some problems parsing this piece of XML using SimpleXML. There is always only one Series element, and a variable number of Episode elements beneath. I want to parse XML so I can store the Series data in one table, and all the Episode data in another table. XML: <Data> <Series> <id>80348</id> <Genre>|Acti...

SimpleXMLElement to PHP Array

Variable $d comes from file_get_contents function to a url. $answer = @new SimpleXMLElement($d); Below is output of the print_r($answer): SimpleXMLElement Object ( [Amount] => 2698 [Status] => OK [State] => FL [Country] => USA ) How can I retrieve value of each element and add to an array? can't figure it out. ...

asXML() Problem

Hello, I wrote this code to quickly edit an existing XML file and save changes to the file. However, it doesn't seem to be writing my data to the xml file. Am I using asXML() wrong? Thanks for your help. <?php $xml = simplexml_load_file("../xml/emp.xml"); $xml->employee[0]['empID'] = $_POST['empID']; $xml->employee[0]->empFN =...

Is it possible to cast a SimpleXML object to a DOMDocument object in PHP?

As a follow up to my earlier question, I'm thinking of using simplexml_load_file to load an XML file from a URL. Would it be possible for me to turn that SimpleXML object to a DOMDocument object via (DOMDocument)$my_simplexml? ...

Read XML with PHP

I am trying to check a field in some XML that is returned from an outside. The XML is returned in a variable call $out and when you view the source of the page you get a XML output of the following, <?xml version="1.0" encoding="UTF-8"?> <ResponseBlock Live="FALSE" Version="3.51"> <Response Type="AUTH"> <OperationResponse> ...

PHP get values from SimpleXMLElement array

I have this: [1]=> object(SimpleXMLElement)#6 (1) { ["@attributes"]=> array(14) { ["name"]=> string(5) "MySQL" ["acknowledged"]=> string(1) "1" ["comments"]=> string(1) "1" ["current_check_attempt"]=> string(1) "1" ["downtime"]=> string(1) "0" ["last_check"]=> string(19) "2010-05-01 ...

Simple XML parsing error

I'm trying to iterate through a Twitter XML File, where the container tag is <users>, and each user is <user>. I need to create a variable $id based on the XML attribute <id> for each user. Username is already instantiated. $url = "http://api.twitter.com/1/statuses/friends/$username.xml"; $xmlpure = file_get_contents($url); $listxml =...

PHP+MYSQL Server Config

Hi guys, I am parsing an XML file with PHP and inserting the rows in a MYSQL database. I am using PHP simplexml_load_files to load the XML and a foreach to loop through the array and insert the rows into my database. It works perfectly fine with small files i am testing, but it comes to reality I need to parse a large 500mb XML file a...

Simple XML variable returns "0"

Ok, so im working with tumblr's API and im using SimpleXMLElement with php and ive run into a problem. Basically, when I call on a variable it just prints a zero. for instance : <?php echo $data->posts->post[0]->photo-url[5]; ?> This just breaks the page, and when I leave out the [5] it just prints zero I want to echo the photo-url...

PHP: How to get <br/> working in a simplexml_load_file() var.

Hi everybody! I am loading an xml in php via simplexml_load_file(). I load the file with that: $xml = simplexml_load_file('flash/datas/datas.xml'); And the access my content like that: $descText = $xml->aboutModule->chocolaterie->desc The text from desc is well registred in my $descText, but all the <br/> of the text disappear....

Get root node of XML doc using simplexml

Using simplexml_load_string() how do I get "ForgotPassword" from the following XML? <?xml version="1.0" encoding="utf-8"?> <ForgotPassword> <version>1.0</version> <authentication> <login>username</login> <apikey>login</apikey> </authentication> <parameters> <emailAddress>[email protected]</emai...

PHP simplexml Entities

What's going one here? $string = <<<XML <?xml version="1.0" encoding="UTF-8"?> <album> <img src="002.jpg" caption="w&aacute;ssup?" /> </album> XML; $xml = simplexml_load_string($string); // $xmlobj = simplexml_load_file("xml.xml"); // same thing echo "<pre>"; var_dump($xml); echo "</pre>"; Error: Warning: simplexml_...