Recent Topics

1 Dec 11, 2006 09:33    

Hi,

I was wondering if anyone could help me out with generating xml output instead of the regular xhtml files using skins.

I wish to incorporate b2evolution blog on our gaming site www.zapak.com
and we are mostly using xslt & ajax for template creation.

So essentially what i require is to generate xml file output within the php code instead of xhtml output.

After having gone through the code of b2evolution blog I require the array output to be in xml.

Could someone help me out as to where exactly do i need to include the following code for dynamically outputting xml files from mysql blog db in b2evolution blog database.

function array_to_xml($array, $level=1) {
        $xml = '';
    foreach ($array as $key=>$value) {
		$key = ereg_replace('\.','dot_',$key);
        $key = strtolower($key);
        if (is_object($value)) {$value=get_object_vars($value);}// convert object to array
        if (is_array($value)) {
            $multi_tags = false;
            foreach($value as $key2=>$value2) {
			$key2 = ereg_replace('\.','dot_',$key2);
             if (is_object($value2)) {$value2=get_object_vars($value2);} // convert object to array
                if (is_array($value2)) {
                    $xml .= str_repeat("\t",$level)."<$key>\n";
                    $xml .= array_to_xml($value2, $level+1);
                    $xml .= str_repeat("\t",$level)."</$key>\n";
                    $multi_tags = true;
                } else {
                    if (trim($value2)!='') {
                        if (htmlspecialchars($value2)!=$value2) {
                            $xml .= str_repeat("\t",$level).
                                    "<$key2><![CDATA[$value2]]>". // changed $key to $key2... didn't work otherwise.
                                    "</$key2>\n";
                        } else {
                            $xml .= str_repeat("\t",$level).
                                    "<$key2>$value2</$key2>\n"; // changed $key to $key2
                        }
                    }
                    $multi_tags = true;
                }
            }
            if (!$multi_tags and count($value)>0) {
                $xml .= str_repeat("\t",$level)."<$key>\n";
                $xml .= array_to_xml($value, $level+1);
                $xml .= str_repeat("\t",$level)."</$key>\n";
            }
      
         } else {
            if (trim($value)!='') {
             //echo "value=$value<br>";
                if (htmlspecialchars($value)!=$value) {
                    $xml .= str_repeat("\t",$level)."<$key>".
                            "<![CDATA[$value]]></$key>\n";
                } else {
                    $xml .= str_repeat("\t",$level).
                            "<$key>$value</$key>\n";
                }
            }
        }
    }
    return $xml;
}

2 Dec 11, 2006 09:43

You should be able to amend one of the rss skins to suit your needs.

¥

3 Dec 11, 2006 11:13

ok . can u tell me the exactly the point where the arrays values from the database are getting populated or converted to xhtml template.

i mean is that happening with the functions.php

u'r help would be really appreciated.

regards,
prashant

4 Dec 11, 2006 11:47

What I mean is, if you look at skins/_rss2/_main.php you'll see that it already spits out xml so you should be able to alter that skin to spit out the values that you require.

¥

5 Dec 11, 2006 13:20

Ok . got it.

thanks so much. u were indeed a great help.

regards,
Prashant


Form is loading...