2013-04-30 5 views
0

$xml->accommodation['id']은 작동하지만 $xml->information['items']은 왜 작동하지 않습니까? 여기 PHP로 XML 구문 분석이 작동하지 않습니다.

<information items="192"> 
<accommodation id="41457" code="7565E59E-77D8-4E24-8F40-85ABBB99CCD0"/> 
<accommodation id="41597" code="1C858B57-F634-4FBB-877F-1D8831417A8B"/> 
(etc.) 

내 PHP의 : 여기

내 XML의는

$url = "URL TO XML FILE"; 
$xml = simplexml_load_file($url); 

(I는 XML을 사용하여 아주 새로운 해요 경우 당신은 말할 수 없습니다.!)

+0

가능한 단순한 [PHP SimpleXML + 속성 가져 오기] (http://stackoverflow.com/questions/10537657/php-simplexml-get-attribute) - [SimpleXML 기본 사용 예제 ] (http://php.net/simplexml.examples-basic.php) - 다른 많은 것들 옆. 따라서 다음 번에 너무 오래 시도하기 전에 이미 해결책이 없다면 몇 가지 힌트를 줄 수 있습니다. – hakre

답변

0

으로 첫 번째 accommodation 노드의 id 속성을 얻으려면;

$xml->accommodation['id'] 

information 노드 사용의 items 속성을 얻으려면,

$xml['items'] 

예 : ->

<?php 

$str = ' 
    <information items="192"> 
    <accommodation id="30"/> 
    <accommodation id="50"/> 
    <accommodation id="80"/> 
    </information> 
'; 

$xml = simplexml_load_string($str); 

$a = $xml->accommodation['id']; 
$b = $xml['items']; 

echo "$a, $b"; // Output: 30, 192 

?> 

는의 자녀를 의미하며, 예를 체인 될 수있다; $xml->foo->bar['id'].

희망이 있습니다.

+0

정말 고마워요. $ xml [ 'items']는 아마도 내가 시도하지 않은 유일한 것입니다! – MarkHFLA

+0

당신을 환영합니다 :-) –

관련 문제