Created
July 27, 2012 20:52
-
-
Save simshaun/3190426 to your computer and use it in GitHub Desktop.
DomDocument stuff. Showing how to get a node value without recursing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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