欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php解析cas返回的xml解决思路

程序员文章站 2022-05-22 22:25:53
...
php解析cas返回的xml
使用php进行cas验证时,对方返回这么一段xml



zhangjian





于是使用php相关函数进行解析

$str =

zhangjian



EOT;


/*
$validateXML = simplexml_load_string($str);print_r($validateXML);
$successnode = $validateXML->authenticationSuccess[0];
var_dump($successnode);
*/

$xml = new DOMDocument();
$xml -> loadXML($str);
var_dump($xml);


结果都解析不出来,哪位朋友遇到过请指点下,不甚感激!!!
------解决方案--------------------
SimpleXML也是PHP5后提供的一套简单易用的xml工具集,
不过它不适用于包含namespace(命名空间)的xml。
------解决方案--------------------
怎么会?
<br><?php <br />$str = <serviceresponse xmlns:cas="http://www.yale.edu/tp/cas"><br><authenticationsuccess><br><user>zhangjian</user><br><language></language><br></authenticationsuccess><br></serviceresponse><br>EOT;<br><br><br><br>$validateXML = simplexml_load_string($str, null, 0, 'cas', true);<br>print_r($validateXML);<br><br>$successnode = $validateXML-&gt;authenticationSuccess[0];<br>print_r($successnode);<br><br><br>$xml = new DOMDocument();<br>$xml -&gt; loadXML($str);<br>print_r($xml);
SimpleXMLElement Object
(
[authenticationSuccess] => SimpleXMLElement Object
(
[user] => zhangjian
[language] => SimpleXMLElement Object
(
)

)

)
SimpleXMLElement Object
(
[user] => zhangjian
[language] => SimpleXMLElement Object
(
)

)
DOMDocument Object
(
[doctype] =>
[implementation] => (object value omitted)
[documentElement] => (object value omitted)
[actualEncoding] =>
[encoding] =>
[xmlEncoding] =>
[standalone] => 1
[xmlStandalone] => 1
[version] => 1.0
[xmlVersion] => 1.0
[strictErrorChecking] => 1
[documentURI] => file:///D:/AMP/web/
[config] =>
[formatOutput] =>
[validateOnParse] =>
[resolveExternals] =>
[preserveWhiteSpace] => 1
[recover] =>
[substituteEntities] =>
[nodeName] => #document
[nodeValue] =>
[nodeType] => 9
[parentNode] =>
[childNodes] => (object value omitted)
[firstChild] => (object value omitted)
[lastChild] => (object value omitted)
[previousSibling] =>
[attributes] =>
[ownerDocument] =>
[namespaceURI] =>
[prefix] =>
[localName] =>
[baseURI] => file:///D:/AMP/web/
[textContent] =>

zhangjian
php解析cas返回的xml解决思路

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。

相关文章

相关视频