PHP XML Parsing
Posted
by ashchawla
on Stack Overflow
See other posts from Stack Overflow
or by ashchawla
Published on 2010-06-05T21:09:24Z
Indexed on
2010/06/05
21:12 UTC
Read the original article
Hit count: 265
Hi I am making get request in PHP but the parser is having issues. I am looking for a way to retreive the value of URL in the following example. The response xml looks like this.
<?xml version="1.0" encoding="iso-8859-1" standalone="no"?>
<testtemplate JobName="test1">
<Sources>
<Source xmlns="http://www.microsoft.com/test/schema/api">
<System>
<SystemIdentifier>HTTPS</SystemIdentifier>
<URL>http://example.com</URL>
</System>
</Source>
</Sources>
<testtemplate>
and my PHP code looks like this:
$xml = DOMDocument::LoadXML($response);
$mypath = new DOMXPath($xml);
$mypath->registerNamespace("a", "http://www.microsoft.com/test/schema/api");
$url = $mypath->evaluate("/testtemplate/Sources/Source/System/URL");
$message = $url->item(0)->value;
print($message);
Any help would be appreciated.
Thanks Ashish
© Stack Overflow or respective owner