<?xml version='1.0'?>
<error>
<error_detail code="0">Successfully</error_detail>
<error_detail code="1">Invalid Username or Password</error_detail>
<error_detail code="2">No username or password</error_detail>
<error_detail code="3">Session has expired</error_detail>
<error_detail code="4">Date of effectivity cannot be less than</error_detail>
</error>
xpath를 사용하여 "세션이 만료되었습니다"를 어떻게 얻을 수 있습니까?
나는 시도했다 :
$xml = simplexml_load_string($xml_string);
$a = $xml->xpath("//error_detail[@code='3']");
display_output($a);
대신 이것을 얻고 있습니다.
array ( 0 => SimpleXMLElement::__set_state(array( '@attributes' => array ( 'code' => '53', ), )), )
xpath 쿼리는 쿼리가 단일 요소 만 반환하더라도 배열을 반환합니다. 텍스트 값을 얻으려면이 첫 번째 요소를 문자열로 변환해야합니다.
$xml = simplexml_load_string($xml_string);
$a = $xml->xpath("//error_detail[@code=3]");
// convert to string though . ''
var_dump($a[0] . ''); // string(19) "Session has expired"
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다