php解析cas返回的xml
使用php进行cas验证时,对方返回这么一段xml
<br /><cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'><br /> <cas:authenticationSuccess><br /> <cas:user>zhangjian</cas:user><br /> <cas:language></cas:language><br /> </cas:authenticationSuccess><br /></cas:serviceResponse><br />
$str = <<
/*
$validateXML = simplexml_load_string($str);print_r($validateXML);
$successnode = $validateXML->authenticationSuccess[0];
var_dump($successnode);
*/
$xml = new DOMDocument();
$xml -> loadXML($str);
var_dump($xml);
$str = <<
$validateXML = simplexml_load_string($str, null, 0, 'cas', true);
print_r($validateXML);
$successnode = $validateXML->authenticationSuccess[0];
print_r($successnode);
$xml = new DOMDocument();
$xml -> loadXML($str);
print_r($xml);
SimpleXMLElement Object<br>(<br> [authenticationSuccess] => SimpleXMLElement Object<br> (<br> [user] => zhangjian<br> [language] => SimpleXMLElement Object<br> (<br> )<br><br> )<br><br>)<br>SimpleXMLElement Object<br>(<br> [user] => zhangjian<br> [language] => SimpleXMLElement Object<br> (<br> )<br><br>)<br>DOMDocument Object<br>(<br> [doctype] => <br> [implementation] => (object value omitted)<br> [documentElement] => (object value omitted)<br> [actualEncoding] => <br> [encoding] => <br> [xmlEncoding] => <br> [standalone] => 1<br> [xmlStandalone] => 1<br> [version] => 1.0<br> [xmlVersion] => 1.0<br> [strictErrorChecking] => 1<br> [documentURI] => file:///D:/AMP/web/<br> [config] => <br> [formatOutput] => <br> [validateOnParse] => <br> [resolveExternals] => <br> [preserveWhiteSpace] => 1<br> [recover] => <br> [substituteEntities] => <br> [nodeName] => #document<br> [nodeValue] => <br> [nodeType] => 9<br> [parentNode] => <br> [childNodes] => (object value omitted)<br> [firstChild] => (object value omitted)<br> [lastChild] => (object value omitted)<br> [previousSibling] => <br> [attributes] => <br> [ownerDocument] => <br> [namespaceURI] => <br> [prefix] => <br> [localName] => <br> [baseURI] => file:///D:/AMP/web/<br> [textContent] => <br> <br> zhangjian<div class="clear"> </div>