From: pkiddie <pk...@us...> - 2005-08-16 15:24:24
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12333/scripts Modified Files: Tag: development_xmlrqp stackQuestion.php stackXML.php Log Message: Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.13.2.14 retrieving revision 1.13.2.15 diff -C2 -d -r1.13.2.14 -r1.13.2.15 *** stackXML.php 15 Aug 2005 16:09:23 -0000 1.13.2.14 --- stackXML.php 16 Aug 2005 15:24:16 -0000 1.13.2.15 *************** *** 106,110 **** stack_question_validate($question,$errors); ! $xmlDoc = new DOMIT_Document(); $xmlDoc->setNamespaceAwareness(true); //We need namespace awareness here //Append processing instructions --- 106,110 ---- stack_question_validate($question,$errors); ! $xmlDoc = &new DOMIT_Document(); $xmlDoc->setNamespaceAwareness(true); //We need namespace awareness here //Append processing instructions *************** *** 197,200 **** --- 197,201 ---- { $potRespFieldElem = &$xmlDoc->createElementNS('',$potRespKey); //Create a potential response field element + print_r($potRespField); if (is_array($potRespField)) //Test for true/false branches { *************** *** 785,789 **** //2. An XML file with an array of questions. //Either return a question, or quiz data structure, then detect the head element? ! function stack_xml_parse_question_file($fileName) { global $stack_root; --- 786,790 ---- //2. An XML file with an array of questions. //Either return a question, or quiz data structure, then detect the head element? ! function stack_xml_parse_file($fileName) { global $stack_root; *************** *** 819,823 **** { //A list of questions or a quiz? ! $questionList = stack_xml_parse_question_list($xmlDoc); break; } --- 820,825 ---- { //A list of questions or a quiz? ! $quiz = stack_xml_parse_quiz($xmlDoc); ! return $quiz; break; } *************** *** 838,842 **** } ! //This function is called when Quiz->Import is selected. //The user is simply trying to import a quiz file //1. Uploading a XML file containing a quiz --- 840,844 ---- } ! /*//This function is called when Quiz->Import is selected. //The user is simply trying to import a quiz file //1. Uploading a XML file containing a quiz *************** *** 869,873 **** } ! } //This function simply maps from an element in a particular namespace onto the correct stackQuestion/stackQuiz data structure field, --- 871,875 ---- } ! }*/ //This function simply maps from an element in a particular namespace onto the correct stackQuestion/stackQuiz data structure field, *************** *** 878,883 **** global $stackQuestion, $stackQuiz; - //print_r($element->localName); - switch($arrayType) { --- 880,883 ---- *************** *** 888,892 **** if((!empty($questionField['type']) && $questionField['type']=='meta')) { ! show_array($questionField); if ((!empty($questionField['metatag']) && ($questionField['metatag']==$element->localName))) { return $arrayKey; --- 888,892 ---- if((!empty($questionField['type']) && $questionField['type']=='meta')) { ! //show_array($questionField); if ((!empty($questionField['metatag']) && ($questionField['metatag']==$element->localName))) { return $arrayKey; *************** *** 902,908 **** foreach($stackQuiz as $arrayKey=>$quizField) { ! if((!empty($stackQuestion['type']) && $stackQuestion['type']=='meta')) { ! if ($stackQuestion['metatag']==$element->localName) { return $arrayKey; } --- 902,908 ---- foreach($stackQuiz as $arrayKey=>$quizField) { ! if((!empty($quizField['type']) && $quizField['type']=='meta')) { ! if ((!empty($quizField['metatag']) && ($quizField['metatag']==$element->localName))) { return $arrayKey; } *************** *** 918,924 **** function stack_xml_parse_element_into_array(&$element,&$array,$arrayType) { $children = &$element->childNodes; //Retrieve all child nodes ! $noChildren = count($children); //Count the number of ! print_r($noChildren); for ($i = 0; $i < $noChildren; $i++) { --- 918,925 ---- function stack_xml_parse_element_into_array(&$element,&$array,$arrayType) { + show_array($array); + $children = &$element->childNodes; //Retrieve all child nodes ! $noChildren = count($children); //Count the number of children for ($i = 0; $i < $noChildren; $i++) { *************** *** 931,935 **** if (!empty($node->namespaceURI)) { - print_r("Gone here!"); $nodeName = stack_xml_map_element_ns($node,$arrayType); } //We will have a nodeName at this point, whether the actual element or resolved from namespace --- 932,935 ---- *************** *** 947,960 **** //1==element - another child, so recurse else if ($node->childNodes[0]->nodeType==1); ! { //Check whether there are multiple types of the same node within the XML tree $nodeList = &$element->getElementsByTagName("$node->nodeName"); $length = $nodeList->getLength(); //If there are multiple elements of the same name //Deal with arrays of values: for example potential responses and questionVar/answerVar if ($length>1) { ! stack_xml_parse_element_into_array($children[$i],$array[$nodeName][],$arrayType); } --- 947,995 ---- //1==element - another child, so recurse else if ($node->childNodes[0]->nodeType==1); ! { //Check whether there are multiple types of the same node within the XML tree $nodeList = &$element->getElementsByTagName("$node->nodeName"); $length = $nodeList->getLength(); + //Need to check that these nodes are direct children of the current node + for ($j = 0; $j < $length; $j++) { + //Get the item + $item = $nodeList->item($j); + //print_r("List item: ".$item->parentNode->nodeName); + //print_r("<br>"); + //print_r("Parent node: ".$node->parentNode->nodeName); + //print_r("<br>"); + if ($item->parentNode->nodeName!=$node->parentNode->nodeName) + { + $length=1; + } + + } + + //print_r($length); + //show_array($nodeList); + //If there are multiple elements of the same name //Deal with arrays of values: for example potential responses and questionVar/answerVar if ($length>1) { ! switch ($nodeName) ! { ! //We want to resolve assessmentItems to their respective stackQuestion fields ! case('assessmentItem'): { ! stack_xml_parse_element_into_array($children[$i],$array[$nodeName][],'stackQuestion'); ! break; ! } ! ! case('mathQuiz'): { ! stack_xml_parse_element_into_array($children[$i],$array[$nodeName][],'stackQuiz'); ! break; ! } ! ! default: { ! stack_xml_parse_element_into_array($children[$i],$array[$nodeName][],$arrayType); ! break; ! } ! } } *************** *** 962,966 **** else { ! stack_xml_parse_element_into_array($children[$i],$array[$nodeName],$arrayType); } --- 997,1017 ---- else { ! switch ($nodeName) ! { ! case('assessmentItem'): { ! stack_xml_parse_element_into_array($children[$i],$array[$nodeName],'stackQuestion'); ! break; ! } ! ! case('mathQuiz'): { ! stack_xml_parse_element_into_array($children[$i],$array[$nodeName],'stackQuiz'); ! break; ! } ! ! default: { ! stack_xml_parse_element_into_array($children[$i],$array[$nodeName],$arrayType); ! break; ! } ! } } *************** *** 985,1000 **** stack_xml_parse_element_into_array($elements,$question['assessmentItem'],'stackQuestion'); - show_array("stack_xml_parse_question"); - show_array($question); - return $question; } ! function stack_xml_parse_quiz() ! { ! } ! ! function stack_xml_parse_question_list() { } --- 1036,1052 ---- stack_xml_parse_element_into_array($elements,$question['assessmentItem'],'stackQuestion'); return $question; } ! function stack_xml_parse_quiz(&$questionXmlDoc) { + global $namespaces, $stackQuiz; + $quiz = array(); + + $elements = &$questionXmlDoc->documentElement; + + stack_xml_parse_element_into_array($elements,$quiz['mathQuiz'],'stackQuiz'); + + return $quiz; } Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.30.2.9 retrieving revision 1.30.2.10 diff -C2 -d -r1.30.2.9 -r1.30.2.10 *** stackQuestion.php 16 Aug 2005 14:00:59 -0000 1.30.2.9 --- stackQuestion.php 16 Aug 2005 15:24:16 -0000 1.30.2.10 *************** *** 449,453 **** $stackQuestionPotResp['FeedBack']['type']='castext'; $stackQuestionPotResp['FeedBack']['branch']=TRUE; ! // Answer note'; $stackQuestionPotResp['AnswerNote']['type']='string'; $stackQuestionPotResp['AnswerNote']['branch']=TRUE; --- 449,453 ---- $stackQuestionPotResp['FeedBack']['type']='castext'; $stackQuestionPotResp['FeedBack']['branch']=TRUE; ! // 'Answer note'; $stackQuestionPotResp['AnswerNote']['type']='string'; $stackQuestionPotResp['AnswerNote']['branch']=TRUE; |