여러분 모두에게 도움을 주셔서 감사합니다 (특히 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="<ADMIN>"/>
</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'};
}
↴
또는 전체 '<ADMIN>' –$ XML-> 어린이() [0] ->이 (속성)'받는 사람 '] – Andreas
$ xml_string-> 어린이() [0 ] -> attributes() [ '받는 사람']이 공백으로 표시됩니다. Firefox에서 요소 검사를 수행하면 ' '이 표시됩니다. –