how to parse an atom

Discussion in 'PHP' started by shadow_boi, Oct 6, 2008.

  1. #1
    Hi,

    I wrote some codes to parse atom1.0 I can get the link and author. summary and html content also show up. However, as for xhtml content, it is not showing up and I am not sure what I need to do with it.

    Anyone please give me some ideas? Thanks.

    
    
    <?php
    
    $pFile = new SimpleXMLElement('sample.xml', null, true);  
    
    foreach ($pFile->entry as $pChild)
    {	
    	echo "<p>\n";
    	echo "Link is: " .$pChild->link->attributes()->href . "<br />\n";
    	echo "Author is: " . $pChild->author->name . "<br />\n";
    	
    	if (!empty($pChild->content)) {
    		
    		if ($pChild->content->attributes()->type == "xhtml")
    		{
    			echo "Content is: " . str_replace("xhtml:", "", $pChild->content);
    		}
    			
    		
    		echo "Conent is: " . $pChild->content . "<br />\n";
    	}
    	
    	elseif (!empty($pChild->summary)){
    		echo "Summary is: " . $pChild->summary . "<br />\n";
    	}
    	
    	else { 
    	// no conent nor summary, don't need to print	
    	}
    
    	echo "</p>\n";
    }
    
    ?>
    
    
    Code (markup):

    any example entry can be:

    
     <entry>
       <title>Test entry</title>
       <id>http://example.org/article</id>
       <link href="http://example.org/article" />
       <content type="xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml">
         <xhtml:div>This is a <xhtml:em>sample</xhtml:em> content. &amp; <xhtml:img src="http://www.example.com/smiley" alt=":-)" /></xhtml:div>
       </content>
     </entry>
    
    Code (markup):
     
    shadow_boi, Oct 6, 2008 IP
  2. shadow_boi

    shadow_boi Peon

    Messages:
    374
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    anyone please help?
     
    shadow_boi, Oct 7, 2008 IP
  3. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #3
    check out xml_parse_into_struct
     
    javaongsan, Oct 8, 2008 IP