Get XML element by tag name
var_dump($object) outputs the following result:
object(stdClass)#9 (5) {
["data"]=> object(stdClass)#8 {
["validFiling"]=> object(stdClass)#7 {
["indicators"]=> string(6) "MODE_S"
}
["plan"]=> object(stdClass)#6 {
["id"]=> string(10) "xxx"
}
}
}
In this data structure I need to access the content of the field id. I do
this in the following way:
try
{
$object = $client->getPlan($p);
var_dump($object);
}
catch (Exception $e) {
print $e->getMessage();
}
$line = $client->getLastResponse();
$doc = new DOMDocument();
$doc->loadXML($line);
$data = $doc->getElementsByTagName('data');
$fp = $data->getElementsByTagName('plan');
$id = $fp->getElementsByTagName('id');
$fId = $id->item(0)->nodeValue;
And the error is (at the line $fp = $data->getElementsByTagName('plan')):
Call to undefined method DOMNodeList::getElementsByTagName()
How to solve this issue?
No comments:
Post a Comment