Skip to content

Instantly share code, notes, and snippets.

@BillKeenan
Created October 23, 2014 18:39
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 BillKeenan/e4666794b85b51b88eeb to your computer and use it in GitHub Desktop.
Save BillKeenan/e4666794b85b51b88eeb to your computer and use it in GitHub Desktop.
xpath sample
<?php
$string = <<<XML
<?xml version="1.0"?>
<string xmlns="http://www.barefoot.com/Services/">
<PropertyList>
<Property>
<PropertyID>7081</PropertyID>
</Property>
<Property>
<PropertyID>2453</PropertyID>
</Property>
<Property>
<PropertyID>7898</PropertyID>
</Property>
</PropertyList>
</string>
XML;
$doc = new DOMDocument();
$doc->loadXML($string);
$xpath = new DOMXpath($doc);
$xpath->registerNamespace('default','http://www.barefoot.com/Services/');
foreach ($xpath->query("/default:string/default:PropertyList/default:Property/default:PropertyID") as $element) {
print_r($element->nodeValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment