simplexml

PHP: Check SimpleXmlElement for erros

Anyone know how can I check the php SimpleXmlElement Object for errors?I mean if is an valid XML file?I have read the manual a lot..but i don't get it! Best Regards, ...

Parse XML with Namespace using SimpleXML

I have this as xml: <event:event> <event:sessionKey></event:sessionKey> <event:sessionName>Learn QB in Minutes</event:sessionName> <event:sessionType>9</event:sessionType> <event:hostWebExID></event:hostWebExID> <event:startDate>02/12/2009</event:startDate> <event:endDate>02/12/2009<...

How can I parse XML to get multiple text blocks with SimpleXML?

I want to parse some XML that looks like this: <node> This is <child> blah </child> some <child> foo </child> text </node> How do I get access to the text node children in Simple XML? Can I access them in the correct order of text and element children? Do I need some other package for this? ...

How does Simple XML use the [] operator?

In PHP you can use square brackets on an element to access attributes: $node = /* SimpleXMLElement */ $id = $node['id']; What's weird is that $id isn't a string, It's another SimpleXMLElement. Why isn't it a string? I find myself using strval() all over the place on this. How are the square brackets working? Can I do that with my own...

Simple_XML cross-domain file access disabled

I need to retrieve an XML file from another domain I own from PHP. I'm using simple_XML to do it but, apparently, cross-domain is disabled: Warning: simplexml_load_file() [function.simplexml-load-file]: URL file-access is disabled in the server configuration I have no access to server's config (shared hosting). Any clue on ...

How to tell apart SimpleXML objects representing element and attribute?

I need to print arbitrary SimpleXML objects in a specific manner, with special handling of attribute nodes. The problem is that SimpleXML elements and attributes seem to use exactly the same class, attribute node even pretends to support attributes() method, and SimpleXML hides its internals, so there doesn't seem to be any way to tell ...

parse an XML with SimpleXML which has multiple namespaces

Hey there :) I have this ugly XML which has alot of namespaces on it, when I try to load it with simpleXML if i indicate the first namespace I'd get an xml object ,but following tags with other namespaces would not make it to the object. How can I parse this XML ? <?xml version="1.0" encoding="UTF-8"?> <soap-env:Envelope xmlns:soap-e...

In SimpleXML, how can I add an existing SimpleXMLElement as a child element?

I have a SimpleXMLElement object $child, and a SimpleXMLElement object $parent. How can I add $child as a child of $parent? Is there any way of doing this without converting to DOM and back? The addChild() method only seems to allow me to create a new, empty element, but that doesn't help when the element I want to add $child also has...

PHP simpleXML how to save the file in a formatted way?

I'm trying add some data to an existing XML file using PHP's SimpleXML. The problem is it adds all the data in a single line: <name>blah</name><class>blah</class><area>blah</area> ... And so on. All in a single line. How to introduce line breaks? How do I make it like this? <name>blah</name> <class>blah</class> <area>blah</area> I...

Recursive cast from SimpleXMLObject to Array

I need to recursively cast a PHP SimpleXMLObject to an array. The problem is that each sub element is also a PHP SimpleXMLElement. Is this possible? ...

PHP Syntax error with Youtube API: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

I keep getting this error in line 54 and I don't know why. All that I'm trying to do is to process the first entry of the query result: extract it's URL so as to construct an embeddable video object. <?php function extractID($youtubeURL) { //split off the final bit of the URL beginning with ‘=’ $youtubeID = strc...

Getting SimpleXMLElement to include the encoding in output

This: $XML = new SimpleXMLElement("<foo />"); echo($XML->asXML()); ...outputs this: <?xml version="1.0"?> <foo/> But I want it to output the encoding, too: <?xml version="1.0" encoding="UTF-8"?> <foo/> Is there some way to tell SimpleXMLElement to include the encoding attribute of the <?xml?> tag? Aside from doing this: $XML = ...

Looping through a SimpleXML object, or turning the whole thing into an array.

I'm trying to work out how to iterate though a returned SimpleXML object. I'm using a toolkit called Tarzan AWS, which connects to Amazon Web Services (SimpleDB, S3, EC2, etc). I'm specifically using SimpleDB. I can put data into the Amazon SimpleDB service, and I can get it back. I just don't know how to handle the SimpleXML object th...

How do I parse XML from PHP that was sent to the server as text/xml?

I have a client-side script written in jQuery that is sending text/xml data to the server, but I can't figure out how to parse the request since the data is not a query string variable. The jQuery looks like this: jQuery.ajax({ url: "test.php", type: "POST", processData: false, contentType: "text/xml", data: xmlDoc, ...

How do I rearrange XML nodes in PHP with SimpleXML?

I'd like to rearrange elements in the file, I do not want to use another attribute for element ordering/arrangement. ...

SimpleXML: Selecting Elements Which Have A Certain Attribute Value

In an XML document, I have elements which share the same name, but the value of an attribute defines what type of data it is, and I want to select all of those elements which have a certain value from the document. Do I need to use XPath (and if so, could you suggest the right syntax) or is there a more elegant solution? Here's some ex...

Conditional SimpleXML possible?

Hi, I am pulling content from a xml file with simpleXML I was wondering if it is possible to display a certain node depending on the contents of the node. eg. <article> <title>PHP</title> <content>yada yada yada</content> </article> <article> <title>JAVASCRIPT</title> <content>yodo yodo yodo</content> </article> can simpleXML find...

PHP returning page error on simplexml print_r

The problem is only happening with one file when I try to do a DocumentDOM/SimpleXML method, so it seems like the issue is with that file. No clue what it could be. If I do the following: $file = "test1.html"; $dom = DOMDocument::loadHTMLFile($file); $xml = simplexml_import_dom($dom); print_r($xml); in Chrome, I get a "Page Unavaila...

Simple XML not working on client server

I built a site using simpleXML to pull content from XML pages. I just switched the site to the client server and the pages that pull from the XML sheet don't work anymore. Testing server was PHP version 5.2.9 Client server is PHP version 5.2.5 allow_url_fopen is on for both servers. Any ideas? class award{ var $xml; var $awards; ...

Weird stuff when outputing XHTML using SimpleXML

Hi, I'm trying to use SimpleXML to output a well-formed XHTML document. I'm doing it like this: $pbDoc = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; <html xmlns="http://www.w3.org/1999/xhtml"&gt; ...