Page 1 of 1
How to include a xml in a php page
Posted: Mon Jan 28, 2008 7:48 pm
by avsa
I am trying to include a google calendar feed on a hmtl/php page. Google exports its calendars on a nice xml page (
http://www.google.com/calendar/feeds/o5 ... blic/basic ) and I want to separate some entities and include on my page to be styled later through css.
Seems very straightforward but this is my first project on php programming and I keep banging my head. I tried domxml_open_mem and tried a xml parser php class but with no success.
Could anyone point me in the right direction?
thanks a lot
Re: How to include a xml in a php page
Posted: Mon Jan 28, 2008 10:57 pm
by thamizhchelvan
I am using magic parser to parse xml data, try here with your url:
http://www.magicparser.com/demo
Re: How to include a xml in a php page
Posted: Mon Jan 28, 2008 11:13 pm
by hannnndy
use this function which gets the xml stream and then returns the array
Code: Select all
public function xmlToArray($domnode, &$array)
{
$array_ptr = &$array;
$domnode = $domnode->firstChild;
while (!is_null($domnode))
{
if (! (trim($domnode->nodeValue) == "") )
{
switch ($domnode->nodeType)
{
case XML_TEXT_NODE:
{
$array_ptr['data'] = $domnode->nodeValue;
break;
}
case XML_ELEMENT_NODE:
{
$array_ptr = &$array[$domnode->nodeName][];
if ($domnode->hasAttributes() )
{
$attributes = $domnode->attributes;
if (!is_array ($attributes))
{
break;
}
foreach ($attributes as $index => $domobj)
{
$array_ptr[$index] = $array_ptr[$domobj->name] = $domobj->value;
}
}
break;
}
}
if ( $domnode->hasChildNodes() )
{
$this->xmlToArray($domnode, $array_ptr);
}
}
$domnode = $domnode->nextSibling;
}
} // xmlToArray
then use
Code: Select all
$array = array();
$domnode;
print_r(xmlToArray($domnode, &$array));
to view the contents