2016-10-01 3 views
2

어떤 이유로 SimpleXML은 &lt;ADMIN&gt;을 파싱하지 않습니다.PHP SimpleXML이 파싱되지 않습니다. <

내 XML 파일 내용 :

$xml = simplexml_load_file('http://localhost/test/xml.xml'); 

    echo "Recipient:". $xml['email-notification']['@attributes']['recipient']; 

출력받는 사람이다 : "빈"나는에서 ADMIN을 읽을 수있는 방법을

XML 파일을 읽어

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE client-config SYSTEM "asigra_conf_windows.dtd"> 
<notifications> 
    <email-notification recipient="&lt;ADMIN&gt;"/> 
</notifications> 

코드 &lt;ADMIN&gt;?

저는 Apache와 PHP 5.6에서 xampp을 사용하고 있습니다.

+0

또는 전체 '<ADMIN>' –

+0

$ XML-> 어린이() [0] ->이 (속성)'받는 사람 '] – Andreas

+0

$ xml_string-> 어린이() [0 ] -> attributes() [ '받는 사람']이 공백으로 표시됩니다. Firefox에서 요소 검사를 수행하면 ''이 표시됩니다. –

답변

1

여러분 모두에게 도움을 주셔서 감사합니다 (특히 IMSoP, 당신은 htmlspecialchars에 관한 것이 었습니다).

제가 계속 실패한 이유는 매뉴얼을 읽지 않고 사람의 고정 관념을 강화했기 때문입니다.

예를 들어 @http://php.net/manual/en/simplexml.examples-basic.php을 보니 단지 5 분이 걸렸습니다. 또한 왜 json_encode/decode를 사용하면 안되는지 설명합니다.다른 TL 들어

, 박사 사람들, 여기에 내가 지금 사용하고있는 코드의 예는 다음과 같습니다

I는 다음과 같습니다 XML이있을 때 :

<configuration> 
    <setup-config> 
     <account-name>Trump</account-name> 
    </setup-config> 
<configuration> 

$xml = simplexml_load_file('http://localhost/config.xml'); 

echo $xml->{'configuration'}->{'setup-config'}->{'account-name'}; 

 

입니다 :

<configuration> 
    <setup-config> 
     <user-info country-code="826"/> 
    </setup-config> 
<configuration> 

$xml = simplexml_load_file('http://localhost/config.xml'); 

echo $xml->{'configuration'}->{'setup-config'}->{'user-info'}['country-code']; 

 

나는 HTML의 문자와 XML이있을 때 :

<configuration> 
    <defaults-config> 
     <def-notification name="&lt;ADMIN&gt;"/> 
    </defaults-config> 
</configuration> 

 

순회 :

<configuration> 
    <roles-config> 
     <group-role role="administrator" name="Administrators" from="."/> 
     <group-role role="backup-operator" name="Backup Operators" from="."/> 
    </roles-config> 
</configuration> 

$xml = simplexml_load_file('http://localhost/config.xml'); 

foreach ($xml->{'configuration'}->{'roles-config'}->{'group-role'} as $grouproles => $groles) { 
    echo "<tr><td>group role name: ".$groles['name']."</td></tr>"; 
    echo "<tr><td>group role role: ".$groles['role']."</td></tr>"; 
    echo "<tr><td>group role role: ".$groles['from']."</td></tr>"; 
} 

 

간단한 생존 확인 :

$xml = simplexml_load_file('http://localhost/config.xml'); 

if(isset($xml->{'configuration'}->{'setup-config'}->{'account-name'})){ 
    echo $xml->{'configuration'}->{'setup-config'}->{'account-name'}; 
}