Skip to content

Instantly share code, notes, and snippets.

@simshaun
Created July 27, 2012 20:52
Show Gist options
  • Save simshaun/3190426 to your computer and use it in GitHub Desktop.
Save simshaun/3190426 to your computer and use it in GitHub Desktop.
DomDocument stuff. Showing how to get a node value without recursing
<?php
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<document>
<item>
<identifier>4</identifier>
<name>Blah</name>
</item>
<item>
<identifier>18</identifier>
<name>Second One</name>
</item>
</document>
XML;
$dom = new DOMDocument();
$dom->loadXML($xml);
$list = $dom->getElementsByTagName('item');
foreach ($list as $item)
{
/** @var $item DOMElement */
echo $item->getElementsByTagName('identifier')->item(0)->nodeValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment