Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP use dom to import simple XML element with prefix
    text
    copied!<pre><code>$loopc = 0; foreach( $xmls-&gt;url as $url ) { $num = $xmls-&gt;count(); if ( $loopc &lt;= $num ) { insertNode($xmls, 'url['.$loopc.']', 'image:image', NULL); insertNode($xmls, 'url['.$loopc.']-&gt;image', 'image:loc', 'urldata'); $loopc = $loopc+1; } else { break; } } echo $xmls-&gt;asXML(); function insertNode(SimpleXMLElement $xml, $path, $qname, $val) { eval('$cur = $xml-&gt;'.$path.';'); $sd = dom_import_simplexml($cur); $newNode = $sd-&gt;ownerDocument-&gt;createElement($qname, $val); $newNode = $sd-&gt;appendChild($newNode); return simplexml_import_dom($newNode); } </code></pre> <p>and I'm trying to get it to take this XML:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.sitemaps.org/schemas/sitemap-image/1.1" xmlns:video="http://www.sitemaps.org/schemas/sitemap-video/1.1"&gt; &lt;url&gt; &lt;loc&gt;http://truefoodlooks.comcompare.php?id=49&lt;/loc&gt; &lt;/url&gt; &lt;/urlset&gt; </code></pre> <p>and make it look like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.sitemaps.org/schemas/sitemap-image/1.1" xmlns:video="http://www.sitemaps.org/schemas/sitemap-video/1.1"&gt; &lt;url&gt; &lt;loc&gt;http://truefoodlooks.comcompare.php?id=49&lt;/loc&gt; &lt;image:image&gt; &lt;image:loc&gt;urldata&lt;/image:loc&gt; &lt;/image:image&gt; &lt;/url&gt; &lt;/urlset&gt; </code></pre> <p>But when ever I try to do the second <code>insertNode()</code> I get this error:</p> <blockquote> <p>Warning: dom_import_simplexml(): Invalid Nodetype to import in /volume1/web/truefoodlooks/test/index.php on line 47</p> </blockquote> <p>How can I fix this?</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