PHP SimpleXML + Get Attribute

This should work. $id = $xml[“id”]; Your XML root becomes the root of the SimpleXML object; your code is calling a chid root by the name of ‘show’, which doesn’t exist. You can also use this link for some tutorials: http://php.net/manual/en/simplexml.examples-basic.php

edit XML with simpleXML

Sure you can edit with SimpleXML: $input = <<<END <?xml version=’1.0′ standalone=”yes”?> <documents> <document> <name>spec.doc</name> </document> </documents> END; $xml = new SimpleXMLElement($input); $xml->document[0]->name=”spec.pdf”; $output = $xml->asXML(); Take a look at the examples.

php SimpleXML attributes are missing

The simple answer here is not to use print_r() with SimpleXML objects. Because they are wrappers around non-PHP data, functions like that which would normally show the “whole” object don’t really reflect what you’re looking at. The way to access an attribute with SimpleXML is to use the attribute name as though it was an … Read more

PHP get values from SimpleXMLElement array

With SimpleXML, you can get : sub-elements, using object notation : $element->subElement and attributes, using array notation : $element[‘attribute’] So, here, I’d say you’d have to use : echo $child[‘name’]; As a reference, and for a couple of examples, see the Basic usage section of simplexml’s manual. Example #6 should be the interesting one, about … Read more

Getting the text portion of a node using php Simple XML

There might be ways to achieve what you want using only SimpleXML, but in this case, the simplest way to do it is to use DOM. The good news is if you’re already using SimpleXML, you don’t have to change anything as DOM and SimpleXML are basically interchangeable: // either $articles = simplexml_load_string($xml); echo dom_import_simplexml($articles)->textContent; … Read more