php解析cas返回的xml
程序员文章站
2024-02-08 13:26:28
...
使用php进行cas验证时,对方返回这么一段xml
于是使用php相关函数进行解析
结果都解析不出来,哪位朋友遇到过请指点下,不甚感激!!!
zhangjian
于是使用php相关函数进行解析
$str =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); zhangjian
结果都解析不出来,哪位朋友遇到过请指点下,不甚感激!!!
回复讨论(解决方案)
SimpleXML也是PHP5后提供的一套简单易用的xml工具集,
不过它不适用于包含namespace(命名空间)的xml。
怎么会?
EOT; $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); zhangjian
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 )
谢谢唠叨大大,刚刚使用一个方法解决了,不过没有大大的好
$str =EOT;$str = str_replace('cas:', '', $str);$validateXML = simplexml_load_string($str);$successnode = $validateXML->authenticationSuccess[0];echo (string)$successnode->user; zhangjian