What i am basically trying to do is convert an XML feed to an array. For my project i submit a query to a website and they provide me an XML feed with all the data.. I grab this feed via a URL..
I have a function i found on this site that worked perfectly for me
here is the function
//************************
**********
**********
**********
**
$xml = file_get_contents($url);
$doc = domxml_open_mem($xml);
$array = xmlnode2array($doc->root()
);
echo '<strong>This String was made from the contents of the XML Document whihc was recieved live from the vin decoding website: '.$array['decoded_loop']['
decoded_ye
ar'].' '.$array['decoded_loop']['
decoded_ma
ke'].' '.$array['decoded_loop']['
decoded_mo
del'].'</s
trong>';
echo '<pre>';
print_r($array);
echo '</pre>';
/**
* Recursive function to convert xml root node to big assoc array
*/
function xmlnode2array($node, $newMap="") {
static $map;
if (!$map && $newMap) $map = array_flip($newMap); // reverse map
if ($node->type==XML_ELEMENT_
NODE) {
if ($attrArray = $node->attributes()) {
// parse attributes //
foreach($attrArray AS $attr) {
$key = '@' . $attr->name;
if ($map[$key]) $out[$map[$key]] = $attr->value;
else $out[$key] = $attr->value;
}
}
if ($childArray = $node->children()) {
// add child nodes //
foreach($childArray AS $child) {
if ($child->type==XML_ELEMENT
_NODE) {
$tagName = $child->tagname;
if ($tagName=='ARRAY_DATA') {
$out[] = xmlnode2array($child);
} else if ($map[$tagName]) {
$out[$map[$tagName]] = xmlnode2array($child);
} else {
$out[$tagName] = xmlnode2array($child);
}
} else {
if ($content = xmlnode2array($child))
$out = $content;
}
}
}
} else {
// this is a CONTENT NODE //
$out = trim($node->content);
if (!$out) return false;
}
return $out;
}
//************************
**********
**********
**********
*
This worked on my webhost perfectly! problem is i then tried it on my local machine and i get this error!
Fatal error: Call to undefined function domxml_open_mem() in C:\apachefriends\xampp\xam
pp\htdocs\
vin\vindec
oding.php
So i checked to see if i had domxml installed.. the dll php_domxml.dll
is in the extensions folder.. i then uncommented out the line
extension=php_domxml.dll
still didn't work.. i changed the comment in both the php.ini and php5.ini
locally i am using php5 which is a Apachie Friends xamp install running php 5.0.3 on a windows machine. My webserver is 4.3.7 running on a *nix machine