need some one to write a php atom parser

Discussion in 'Programming' started by shadow_boi, Oct 11, 2008.

  1. #1
    job done, and payment sent.

    Thanks soulscratch, however someone else contacted me and finished the job first.
     
    shadow_boi, Oct 11, 2008 IP
  2. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    As Seller:
    100% - 0
    As Buyer:
    100% - 0
    #2
    Think I finally got it, assuming the only namespace you use is xhtml:,

    
    <?php
    error_reporting( E_ALL );
    
    $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")
    		{
    		    $ns = 'http://www.w3.org/1999/xhtml';
    			$thing = $pChild->content->children( $ns )->div->asXML();
    			$thing = str_replace( 'xhtml:', '', $thing );
    			echo $thing;
    		}
    			
    		
    		echo '<br>after';
    		// echo "<br>Conent is: " . $pChild->content->asXML() . "<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):
    xml I used:

    
    <thing>
        <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>
           <author>
    	    <name>John</name>
    	</author>
         </entry>
     </thing>
    
    Code (markup):
    Source output:

    
    <p>
    Link is: http://example.org/article<br />
    Author is: John<br />
    <div>This is a <em>sample</em> content. &amp; <img src="http://www.example.com/smiley" alt=":-)"/></div><br>after</p>
    
    Code (markup):
     
    soulscratch, Oct 11, 2008 IP