2011-08-19 3 views
0

저는 XML에서 최신 코멘트를 얻으려고합니다. 그 예가 여기에 있습니다 : http://dev.smoige.com/discussion.xml?DiscussionID=8. 나는 LastCommentID를 얻을 수 있었다. 그것은 37이라고 말하며,이 형식으로 찾을 수있다. <CommentID>37</CommentID> 그리고 그 밑에는 <Body>this is my damn comment!</Body>이있다. LastCommentID를 사용하여 올바른 CommentID를 선택하고 본문을 가져 오는 방법은 무엇입니까?PHP로 XML 데이터를 가져옵니다. 갇혔어요?

도와주세요.

$latestXml = 'http://dev.smoige.com/discussion.xml?DiscussionID='.$Discussion->DiscussionID; 

     if(!$xml=simplexml_load_file($latestXml)){ 
      trigger_error('Error reading XML file',E_USER_ERROR); 
     } 

    foreach($xml as $user){ 
     $last = $user->LastCommentID.' '; 

    } 

당신에게

답변

0

짧은 답변 감사합니다 XPath를.

여기 좋은 튜토리얼입니다 : 도움말 사람에 대한

http://www.phpeveryday.com/articles/PHP-XML-Tutorial-P848.html

<?php 
    $xml = simplexml_load_file("books.xml") 
     or die("Error: Cannot create object"); 
    // we want to show just <title> nodes 
    foreach($xml->xpath('//title') as $title){ 
    echo $title. "<br />"; 
    } 
?> 
+0

감사합니다. 아무 것도 할 수 없었지만 계속 노력할 것입니다. – Ciprian

관련 문제