Path

ez projects / bcfetchxml / forum / general / bc fetch xml feedback


BC Fetch XML Feedback

You need to be logged in to post messages in the forums. New users may register here.

Brookins Consulting

Member since:
03 April 2003

Posts: 67

Monday 22 June 2009 7:17:21 pm

Hello!

We are very proud to offer the BC Fetch XML extension,
http://projects.ez.no/bcfetchxml

Please provide feedback to the community on how the extension works for you and any features you might think would be useful to add.

If this extension is useful to you please write a positive review, http://projects.ez.no/bcfetchxml/reviews

Cheers,
Brookins Consulting
Up

Julian Mancera

Member since:
08 July 2008

Posts: 1

Tuesday 22 September 2009 10:05:10 pm

Hi BC,

I was implementing a XML file reader and I found your extension. The cache handling seems pretty nice. Regarding the XML handling I checked the simple XML php function and it only handles 1 level depth XMLs. So I implemented a XML to array reader of n levels using the DOMDocument class. Additionally I implement a timeout handling function so Apache does not create many processes if the XML file could not be downloaded. Let me know your comments and can you please check if we can update your operator functionality.




function modify( $tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )


   {        

                


       switch ( $operatorName )


       {


                        case 'getRSS':


                        {                               


                                $xmlCall = $namedParameters['xml_url'];        


                                $stringXml = $this -> getContentURL($xmlCall);


                                if ($stringXml) {


                                        $stringXml = trim($stringXml);


                                        $xml = new DOMDocument('1.0');


                                        $xml->formatOutput = true;                                   


                                        $xml_load = $xml->loadXML( $stringXml);      


                                        if ( $xml_load )


                                        {       


                                                $elementsbytag = $xml->getElementsByTagName($namedParameters['breaking_tag']);


                                                $error = $xml->getElementsByTagName( $namedParameters['error_tag'] );


                                                


                                                if ( $error -> length )


                                                {


                                                        eZLog::write("Bag request. Please review parameters:" . $xmlCall ,'weather.log','extension/aplweatherchannel/var/log');


                                                        $errorMessage=true;


                                                }


                                        }


                                        else


                                        {                                               


                                                eZLog::write("XML couldn't be downloaded or has bad format:" . $xmlCall ,'weather.log','extension/aplweatherchannel/var/log');


                                                 $errorMessage=true;


                                        }       


                                }


                                else 

                                {


                                                eZLog::write("XML couldn't be downloaded or has bad format:" . $xmlCall ,'weather.log','extension/aplweatherchannel/var/log');


                                                 $errorMessage=true;


                                }       


                                


 

                                if ($errorMessage) {


                                        


                                        $operatorValue = array();


                                }else{


                                                                                


                                


                                        $itemsArray = array();


                                        if( $namedParameters['offset'] > $elementsbytag -> length )


                                        {               


                                                $offset = 0;


                                        }


                                        else


                                        {


                                                $offset = $namedParameters['offset'];


                                        }       


                                                


                                        if( ($namedParameters['limit'] + $offset) > $elementsbytag -> length )


                                        {                                               


                                                $limit = $elementsbytag -> length;


                                        }


                                        else


                                        {


                                                $limit = $namedParameters['limit'] + $offset;   


                                        }


                                        


                                        for( $i = $offset ; $i < $limit ; $i++)


                                        {  

                                          $itemsArray[] = $this -> getchildrenRSS($elementsbytag -> item($i) );


                                        }


                                        $operatorValue = $itemsArray;                                          


                                }


                        


                        }break;


                        


                


      }


   }


        function getchildrenRSS($children_object)


        {


                


                foreach( $children_object -> childNodes as $childNode )


                {


                        if( get_class( $childNode ) == 'DOMText' )


                        {


                                if( !$childNode -> hasChildNodes() )


                                {


                                        if( !$childNode -> isWhitespaceInElementContent() )  


                                                $childrenArray['value'] = $childNode -> nodeValue; 

                                }


                        }


                        elseif( get_class( $childNode ) == 'DOMElement' )


                        {


                                $childrenArray['children'][] = $this -> getchildrenRSS( $childNode );


                        }                       


                }                       


                


                if( $children_object -> hasAttributes() )


                {                       


                        foreach( $children_object -> attributes as $attrNode ) 

                        {


                                //print_r( $attrNode -> value);


                                $childrenArray['@attributes'][$attrNode -> name] = $attrNode -> value;            


                        }       


                }


                return $childrenArray;


   }


 

        


        function getContentURL($url, $use_proxy = true)


        {


          

                $ctx = stream_context_create(array('http' => array('timeout' => 3)));


                $content_string = file_get_contents($url,false, $ctx);


                 return trim($content_string); 

        }


 

 

Up

You need to be logged in to post messages in the forums. New users may register here.