2015-02-06 4 views
2

이것은 중복 될 수 있지만 지금까지는 아무 것도 발견하지 못했습니다.SimpleXML을 사용하는 xml 요소/노드 수

simplexml을 사용하여 nodes/childs의 파일을 XML으로 계산하려고합니다.

나는 이것을 시도했다.

$xml = simplexml_load_file("./file.xml"); 
echo count($xml->rss->channel->item); 

echo count($xml->item); 

하지만 단지 0 출력

. 여기

XML

<?xml version="1.0"?> 
<rss xmlns:xsd="http://www.w3.org/2001/XMLSchema"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:g="http://base.google.com/ns/1.0" version="2.0"> 
    <channel> 
    <item> 
     <title>PUDRA Pudra Ceket Ceket</title> 
     <link>http://www.trendyol.com//Pudra-Ceket-IW6140005046/UrunDetay/31066/9188683?</link> 
     <description>36 pudra pudra ceket ıw6140005046 ipekyol ceket kadın</description> 
     <g:urunid>1423905</g:urunid> 
     <g:id>1423905_14</g:id> 
    </item> 
    <item> 
     .... 
    </item> 
+0

단일 항목을 인쇄하는 동안 ' 1423905_14'을 선택하지 않았습니다. – Mubin

답변

2

의 스냅 샷이 당신을 위해 일한다이다 :

echo count($xml->channel->item); 

편집 :

왜 당신이이 방법이? 형태 simplexml_load_file() 때문에이 (print_r($xml);)와 같은 구조를 얻을 :

SimpleXMLElement Object 
(
    [@attributes] => Array 
     (
      [version] => 2.0 
     ) 

    [channel] => SimpleXMLElement Object 
     (
      [item] => Array 
       (

내가 (위) 말했듯이 구조의 개체를 액세스해야하기 때문에.

+0

예, 작동 .. 감사합니다. – Mubin

+1

@MubinKhalid 여러분 안녕하세요! 좋은 하루 보내십시오 : D – Rizier123

+0

내가 뭘 잘못하고 있었는지 말씀해 주시겠습니까? – Mubin