Getting values from SimpleXMLElement or SimpleType with hypen in php
by rajesh[ Edit ] 2012-05-11 00:47:49
Consider $responseXml is a SimpleXMLElement with contains certain nodes with hypen "-" in its name
The following code will not work
foreach ($responseXml->xpath('/path/result') as $resultNode) {
$cid = $resultNode->id;
$cname = (string)$resultNode->data->gen_info->c-name;
}
We will always get $cname as 0
The fix is using {'...'}
$cname = (string)$resultNode->data->gen_info->{'c-name'};