Note that there are some explanatory texts on larger screens.

plurals
  1. POSimpleXML Reading node with a hyphenated name
    text
    copied!<p>I have the following XML:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;gnm:Workbook xmlns:gnm="http://www.gnumeric.org/v10.dtd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gnumeric.org/v9.xsd"&gt; &lt;office:document-meta xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:ooo="http://openoffice.org/2004/office" office:version="1.1"&gt; &lt;office:meta&gt; &lt;dc:creator&gt;Mark Baker&lt;/dc:creator&gt; &lt;dc:date&gt;2010-09-01T22:49:33Z&lt;/dc:date&gt; &lt;meta:creation-date&gt;2010-09-01T22:48:39Z&lt;/meta:creation-date&gt; &lt;meta:editing-cycles&gt;4&lt;/meta:editing-cycles&gt; &lt;meta:editing-duration&gt;PT00H04M20S&lt;/meta:editing-duration&gt; &lt;meta:generator&gt;OpenOffice.org/3.1$Win32 OpenOffice.org_project/310m11$Build-9399&lt;/meta:generator&gt; &lt;/office:meta&gt; &lt;/office:document-meta&gt; &lt;/gnm:Workbook&gt; </code></pre> <p>And am trying to read the office:document-meta node to extractthe various elements below it (dc:creator, meta:creation-date, etc.)</p> <p>The following code:</p> <pre><code>$xml = simplexml_load_string($gFileData); $namespacesMeta = $xml-&gt;getNamespaces(true); $officeXML = $xml-&gt;children($namespacesMeta['office']); var_dump($officeXML); echo '&lt;hr /&gt;'; </code></pre> <p>gives me:</p> <pre><code>object(SimpleXMLElement)[91] public 'document-meta' =&gt; object(SimpleXMLElement)[93] public '@attributes' =&gt; array 'version' =&gt; string '1.1' (length=3) public 'meta' =&gt; object(SimpleXMLElement)[94] </code></pre> <p>but if I try to read the document-meta element using:</p> <pre><code>$xml = simplexml_load_string($gFileData); $namespacesMeta = $xml-&gt;getNamespaces(true); $officeXML = $xml-&gt;children($namespacesMeta['office']); $docMeta = $officeXML-&gt;document-meta; var_dump($docMeta); echo '&lt;hr /&gt;'; </code></pre> <p>I get</p> <pre><code>Notice: Use of undefined constant meta - assumed 'meta' in /usr/local/apache/htdocsNewDev/PHPExcel/Classes/PHPExcel/Reader/Gnumeric.php on line 273 int 0 </code></pre> <p>I assume that SimpleXML is trying to extract a non-existent node "document" from $officeXML, then subtract the value of (non-existent) constant "meta", resulting in forcing the integer 0 result rather than the document-meta node.</p> <p>Is there a way to resolve this using SimpleXML, or will I be forced to rewrite using XMLReader? Any help appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload