From: pkiddie <pk...@us...> - 2005-08-05 10:45:13
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27968/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.6 retrieving revision 1.13.2.7 diff -C2 -d -r1.13.2.6 -r1.13.2.7 *** stackXML.php 4 Aug 2005 12:09:43 -0000 1.13.2.6 --- stackXML.php 5 Aug 2005 10:44:32 -0000 1.13.2.7 *************** *** 25,28 **** --- 25,40 ---- $xmlElements = array(); + //$namespaces data structure + $namespaces['xs']['namespace'] = 'http://www.w3.org/2001/XMLSchema'; //Default namespace + $namespaces['xs']['id'] = 'xs'; //REQUIRED FOR SCHEMA + + $namespaces['dc']['namespace'] = 'http://purl.org/dc/elements/1.1/'; //Dublin core namespace + $namespaces['dc']['id'] = 'dc'; //The ID prepended to our elements that use DC + $namespaces['dc']['location'] = 'dc.xsd'; //The actual location of the dublin core schema + + $namespaces['lom']['namespace'] = 'http://www.imsglobal.org/xsd/imsmd_v1p2';//etc. + $namespaces['lom']['id'] = 'lom'; + $namespaces['lom']['location'] = 'imsmd_v1p2.xsd'; + /** * Writes a single stackQuestion data structure to an XML string. *************** *** 61,64 **** --- 73,207 ---- } + //Creates an AssessmentItem fragment, and returns the head DOMIT_Element + function stack_xml_create_question_new($question) + { + global $stackQuestion, $stack_ver, $namespaces; + + // Don't export questionID + if (array_key_exists('questionID',$question)) { + unset($question['questionID']); + } + + // Make sure the question is validated. + stack_question_validate($question,$errors); + + // Can't have numbered fields in the XML + // (1) Remove keyvals fields + foreach($stackQuestion as $qfield => $attribs) { + if ('keyval' == $attribs['type'] and array_key_exists($qfield,$question)) { + unset($question[$qfield]); + } + } + + $xmlDoc = new DOMIT_Document(); + $xmlDoc->setNamespaceAwareness(true); //We need namespace awareness here + + $questionFrag = new DOMIT_Element('assessmentItem'); + $questionVersionAttr = new DOMIT_Attr('version'); + $questionVersionAttr->nodeValue = $stack_ver['release']; + + $questionFrag->setAttributeNode($questionVersionAttr); + + //Now construct the main body of the XML file + //1. The metadata + //Iterate through the question fields, then picking out the respective fields - and only write out if they contain a metatag + if (is_array($question)) { + foreach($question as $tag => $qfield) + { + print_r($question); + if (!empty($qfield['type']) && $qfield['type']=='meta') + { + switch ($qfield['metatype']) + { + case('dublincore'): + { + $metaElement =&$xmlDoc->createElementNS($namespaces['dc']['namespace'],"{$namespaces['dc']['id']}:{$qfield['metatag']}"); + break; + } + + case('lom'): + { + $metaElement =&$xmlDoc->createElementNS($namespaces['lom']['namespace'],"{$namespaces['lom']['id']}:{$qfield['metatag']}"); + break; + } + + case('stack'): + { + $metaElement =&$xmlDoc->createElementNS('',"$tag"); + break; + } + + case('default'): + { + $metaElement =&$xmlDoc->createElementNS('',"$tag"); + break; + } + + $questionFrag->appendChild($metaElement); + } + + + } + } + } + + $xmlDoc->appendChild($questionFrag); + + return $xmlDoc; + } + + function stack_xml_create_question_frag_new($question) + { + if (is_array($question)) { + foreach($question as $tag => $data) { + if (is_array($data)) { + + print_r($data); + // Deal with arrays of numbered attributes. + if (array_key_exists('0',$data)) { + $pad = str_pad('',$depth); + $xml .= $pad."<$tag>\n"; + foreach ($data as $key => $orderdata) { // Do for each one. + $xml .= $pad." <{$tag}_ord order=\"$key\">\n".stack_xml_create_question_frag($orderdata,$depth+6)."$pad </{$tag}_ord>\n"; + } + $xml .= $pad."</$tag>\n"; + } else { + // Just a regular open tag. + $pad = str_pad('',$depth); + $xml .= $pad."<$tag>\n".stack_xml_create_question_frag($data,$depth+4)."$pad</$tag>\n"; + } + } else { // We need a closed tag. + if ('' != trim($data) ) { + $pad = str_pad('',$depth); + $xml .= $pad."<$tag>".stack_s($data)."</$tag>\n"; + } + } + } + } + } + + //Takes the assessmentItem fragment, constructs a filename and saves it out to XML + //Returns true if file was successfully written out, false otherwise + function stack_xml_write_question_new($question,$directory) + { + //Create question filename + if ($question['questionName'] != '') { + $xml_file_name = $question['questionName'].".xml"; + } else { + $xml_file_name = 'stack_'.$question['questionID'].".xml"; + } + + $xmlDoc = &stack_xml_create_question_new($question); + + $success = $xmlDoc->saveXML($directory."/".$xml_file_name,true); + + if (!$success) + { + return null; + } + + return $xml_file_name; + } + /** * Takes a stackQuestion array, and returns an XML string fragment. *************** *** 442,446 **** //Data structures that must be output in schema format ! global $stackQuestion, $stackOptions, $stackQuestionPotResp, $stack_ver, $sqlToSchemaMapping, $xmlElements; $xmlElements = array(); //Empty existing array --- 585,589 ---- //Data structures that must be output in schema format ! global $stackQuestion, $stackOptions, $stackQuestionPotResp, $stack_ver, $sqlToSchemaMapping, $xmlElements, $namespaces; $xmlElements = array(); //Empty existing array *************** *** 450,465 **** include($filename); - //$namespaces data structure - $namespaces['xs']['namespace'] = 'http://www.w3.org/2001/XMLSchema'; //Default namespace - $namespaces['xs']['id'] = 'xs'; //REQUIRED FOR SCHEMA - - $namespaces['dc']['namespace'] = 'http://purl.org/dc/elements/1.1/'; //Dublin core namespace - $namespaces['dc']['id'] = 'dc'; //The ID prepended to our elements that use DC - $namespaces['dc']['location'] = 'dc.xsd'; //The actual location of the dublin core schema - - $namespaces['lom']['namespace'] = 'http://www.imsglobal.org/xsd/imsmd_v1p2';//etc. - $namespaces['lom']['id'] = 'lom'; - $namespaces['lom']['location'] = 'imsmd_v1p2.xsd'; - $types = array(); //Array of metadata types - dublincore, stack, lom etc. // $xmlElements = array(); //A collection of elements which must be linked together via a 'root' element - in this case: AssessmentItem --- 593,596 ---- |