From: pkiddie <pk...@us...> - 2005-08-12 13:52:01
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5896/scripts Modified Files: Tag: development_xmlrqp stackXML.php Log Message: Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.13.2.11 retrieving revision 1.13.2.12 diff -C2 -d -r1.13.2.11 -r1.13.2.12 *** stackXML.php 10 Aug 2005 11:49:12 -0000 1.13.2.11 --- stackXML.php 12 Aug 2005 13:51:54 -0000 1.13.2.12 *************** *** 841,844 **** --- 841,883 ---- } + function stack_xml_parse_element_into_array(&$element,&$array) + { + $noChildren = count($element); + + for ($i = 0; $i < $noChildren; $i++) { + $node = &$element[$i]; + + print_r($node->nodeName); + + //Add this element to the array given, depending on the type of node found + //Does it have children + //If so which type? + //If node has children + if ($node->childNodes!=null) + { + //We need to check what type these child nodes are.. + //3==text node - not really a child as such + if ($node->childNodes[0]->nodeType==3) + { + //print_r($node->nodeName); + $array[$node->nodeName]=$node->getText(); + } + + //1==element - another child, so recurse + else if ($node->childNodes[0]->nodeType==1); + { + print_r("Here"); + stack_xml_parse_element_into_array($element[$node->nodeName],$array); + } + } + + //If node has not got children + else + { + $array[$node->nodeName]=$node->getText(); + } + } + } + function stack_xml_parse_question(&$questionXmlDoc) { *************** *** 851,856 **** //1. Retrieve dublin core, learning object model and stack core elements if they exist ! $nodeList = &$questionXmlDoc->documentElement->childNodes; foreach ($nodeList as $node) { --- 890,914 ---- //1. Retrieve dublin core, learning object model and stack core elements if they exist ! $elements = &$questionXmlDoc->documentElement->childNodes; + stack_xml_parse_element_into_array($elements,$question); + + show_array($question); + /*// Alle Nodes des Elemnts an array übergeben + + //add ampersand (&) after equal sign for PHP4 compatability + $node =& $elements->item($i); + + //$numChildren = $node->childCount; + + for ($j = 0; $j < $numChildren; $j++) { + ///get reference to current child node + $currChildNode =& $node->childNodes[$j]; + + //echo node value of text node + echo $currChildNode->getText(); + } + } + foreach ($nodeList as $node) { *************** *** 863,868 **** --- 921,959 ---- { print_r($node->nodeName); + $question[$node->nodeName]=$node->getText(); } + //1==element - another child + else if ($node->childNodes[0]->nodeType==1); + { + //Therefore we have an array of data + $question[$node->nodeName]= array(); + + foreach ($node->childNodes as $child) + { + if ($child->childNodes!=null) + { + if ($child->childNodes[0]->nodeType==3) + { + $question[$node->nodeName][$child->nodeName]==$child->getText(); + } + + //Must have more elements + else if ($child->childNodes[0]->nodeType==1) + { + $question[$node->nodeName][$cihld->nodeName]==array(); + } + + } + + //Else childnode does not contain data + else + { + $question[$node->nodeName][$child->nodeName]=$child->getText(); + + //We need to recurse + + + *************** *** 873,876 **** --- 964,968 ---- { print_r($node->nodeName); + $question[$ode->nodeName]=$node->getText(); } } |