SimpleXML Reading node with a hyphenated name

Your assumption is correct. Use

$officeXML->{'document-meta'}

to make it work.

Please note that the above applies to Element nodes. Attribute nodes (those within the @attributes property when dumping the SimpleXmlElement) do not require any special syntax to be accessed when hyphenated. They are regularly accessible via array notation, e.g.

$xml = <<< XML
<root>
    <hyphenated-element hyphenated-attribute="bar">foo</hyphenated-element>
</root>
XML;
$root = new SimpleXMLElement($xml);
echo $root->{'hyphenated-element'}; // prints "foo"
echo $root->{'hyphenated-element'}['hyphenated-attribute']; // prints "bar"

See the SimpleXml Basics in the Manual for further examples.

Tags:

Php

Simplexml