Skip to content

Instantly share code, notes, and snippets.

@igstan
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igstan/9654eca0db804c8e87bd to your computer and use it in GitHub Desktop.
Save igstan/9654eca0db804c8e87bd to your computer and use it in GitHub Desktop.
<?php
$xml = '
<root>
<child>
some text
</child>
some other text
<![CDATA[
a CDATA node
]]>
<!-- a comment node -->
<?processing-instruction-node ?>
</root>
';
$dom = DOMDocument::loadXML($xml);
foreach ($dom->firstChild->childNodes as $node) {
var_dump($node->nodeName);
}
// Outputs this:
//
// string(5) "#text"
// string(5) "child"
// string(5) "#text"
// string(14) "#cdata-section"
// string(5) "#text"
// string(8) "#comment"
// string(5) "#text"
// string(27) "processing-instruction-node"
// string(5) "#text"
foreach ($dom->getElementsByTagName('*') as $node) {
var_dump($node->nodeName);
}
// Outputs this:
//
// string(4) "root"
// string(5) "child"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment