0

I have no idea what kind of XML this is and how to read it with simplexml in PHP...

<abc:documents count="1">
<def:doc>
<def:serial-item>
<ghi xml:lang="en" version="5.1">
<item-info>...</item-info>
<jkl:something>...</jkl:something>
<head>...</head>
<body view="all">...</body>
</ghi>
</def:doc>
</abc:documents>

When I simply do:

$xml = simplexml_load_file('file.xml'); //with above content
var_dump($xml);

I get:

object(SimpleXMLElement)#1 (1) { ["@attributes"]=> array(1) { ["count"]=> string(1) "1" } }

rene
  • 41,474
  • 78
  • 114
  • 152
Bob van Luijt
  • 7,153
  • 12
  • 58
  • 101
  • 1
    The element names with colons in are in "namespaces". Search using that keyword, and you will see lots of examples; basically, you use [the `->children()` method](http://php.net/manual/en/simplexmlelement.children.php) to select the namespace you need. – IMSoP Sep 11 '13 at 18:25
  • Also, it's best not to rely on `print_r`, `var_dump`, etc with SimpleXML, as it is more of an API than an object, and those functions don't tell you all there is to know. You might like to try [these debug functions I wrote](https://github.com/IMSoP/simplexml_debug) instead. – IMSoP Sep 11 '13 at 18:26
  • What is the header of your XML and it seems you're mixing up unrelated namespaces to what it was originally? – Prix Sep 11 '13 at 18:29
  • Thanks all. Just searching for "SimpleXML" and "Namespace" did it. http://www.sitepoint.com/simplexml-and-namespaces/ – Bob van Luijt Sep 12 '13 at 09:43

0 Answers0