Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 29-06-2009
Member
 
Join Date: May 2009
Posts: 503
XML to ARRAY

I had a problem were i couldn?t get my xml feeds into an array.I have an easy xml file in some menu items. Now, I want that xmlnodes to be utilized to build a menu. Could you guys help me out for the same please ?
Reply With Quote
  #2  
Old 29-06-2009
Member
 
Join Date: Feb 2009
Posts: 673
Re: XML to ARRAY

You can use this script for the same :

Quote:
function fetch_xml($xml){

if(is_file($xml)){
$xml_data = file_get_contents($xml);
}
else{
$xml_data = $xml;
}
$parser = xml_parser_create();
xml_parse_into_struct($parser, $xml_data, &$assoc_arr, &$idx_arr);
xml_parser_set_option($parser, OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, OPTION_SKIP_WHITE, 1);
$root_tag = $assoc_arr[0]['tag'];
$base_tag = strtolower($assoc_arr[1]['tag']);
$i = 0;
foreach($assoc_arr as $key => $element){
if($element['tag'] != $root_tag){
if(!preg_match('/^\s+$/', $element['value'])){
$tag = strtolower($element['tag']);
$items[$i][$tag] = $element['value'];
if($tag == $base_tag){
$i++;
}
}
elseif(isset($element['attributes'])){
$items[$i]['id'] = $element['attributes']['ID'];
}
}
}

return $items;
}

$items = fetch_xml('articles.xml');

echo '<pre>';
print_r($items);
echo '</pre>';
Reply With Quote
  #3  
Old 29-06-2009
Member
 
Join Date: Feb 2007
Posts: 234
Re: XML to ARRAY

This can help you to use use xmlnodes to build a menu:
Quote:
var my_xml = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success) {
if (success) {
var myArray = my_xml.firstChild.childNodes;
// your xml file is now an array
} else {
trace("XML_Error Loading ");
}
};
my_xml.load("xmlFile.xml");
Reply With Quote
  #4  
Old 29-06-2009
Member
 
Join Date: Feb 2009
Posts: 162
Re: XML to ARRAY

Its really great, however it seems to attibutefunctie miss. When you load the xml in which the father node has attributes and child Nodes of the child Nodes in series will, however, as only nodes with attributes is the attributes set in the series. It would be great if it somehow did both.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "XML to ARRAY"
Thread Thread Starter Forum Replies Last Post
Array of array in PHP cyber-noob Software Development 4 26-02-2010 05:13 PM
C# array help Daren Software Development 5 03-01-2010 07:12 AM
Assigning an array to an array MACE Software Development 3 18-11-2009 05:19 PM
Array Functions in PHP SuperXCM Software Development 2 26-03-2009 10:57 AM
JAVA array Daren Software Development 2 06-03-2009 06:13 PM


All times are GMT +5.5. The time now is 09:01 PM.