From: pkiddie <pk...@us...> - 2005-08-02 16:00:49
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1984/scripts Modified Files: Tag: development_xmlrqp stackQuestion.php stackXML.php Log Message: Updated potential responses structure to indicate to XML schema parser whether type is global or part of a true/false branch. Schema creation for an 'assessmentItem' completed - just needs more elegence! Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.13.2.3 retrieving revision 1.13.2.4 diff -C2 -d -r1.13.2.3 -r1.13.2.4 *** stackXML.php 1 Aug 2005 21:56:34 -0000 1.13.2.3 --- stackXML.php 2 Aug 2005 16:00:27 -0000 1.13.2.4 *************** *** 1344,1347 **** --- 1344,1360 ---- } + /*function stack_xml_create_question($question) + { + //This time we want namespace awareness when producing our XML files + $dom = new DOMIT_DOCUMENT(); + $dom->SetNamespaceAwareness(true); + + + } + + function stack_xml_create_quiz($quiz) + { + }*/ + /** * Creates a question schema for the specified question *************** *** 1359,1367 **** */ //Creates a question schema using the stackQuestion data structure //Writes out each of the possible entities that can exist in the XML file, and in the case of the metadata //The particular standard it belongs to ! ! function stack_xml_create_question_schema($questionSchemaLocation,$questionSchemaVersion) { include('stackstd.php'); //For writing out schema version: use stack version --- 1372,1392 ---- */ + //Only difference between quiz and question is quiz has multiple questions, or 'AssessmentItems' - each quiz also + //has global options, and a global metadata structure + function stack_xml_create_quiz_schema($quizSchemaLocation,$quizSchemaVersion) + { + + + } + + /*function stack_xml_create_question_schema($questionSchemaLocation,$questionSchemaVersion) + { + + }*/ + //Creates a question schema using the stackQuestion data structure //Writes out each of the possible entities that can exist in the XML file, and in the case of the metadata //The particular standard it belongs to ! function stack_xml_create_question_schema() { include('stackstd.php'); //For writing out schema version: use stack version *************** *** 1374,1381 **** include($filename); ! $dublinCoreUri = 'http://purl.org/dc/elements/1.1'; ! $learningObjectUri = 'http://www.imsglobal.org/xsd/imsmd_v1p2'; $types = array(); //Array of metadata types - dublincore, stack, lom etc. // Don't export questionID within metadata --- 1399,1411 ---- include($filename); ! $dublinCoreUri = 'http://purl.org/dc/elements/1.1/'; ! $learningObjectUri = 'http://www.imsglobal.org/xsd/imsmd_v1p2'; //Namespace does not seem to resolve to anything ! ! $dublinCoreLocation = 'dc.xsd'; ! $learningObjectLocation = '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 // Don't export questionID within metadata *************** *** 1392,1395 **** --- 1422,1427 ---- //$dom->SetNamespaceAwareness(true); //We dont want to use namespace awareness for schema generation + $dom->appendChild($dom->createProcessingInstruction('xml', "version=\"1.0\" encoding=\"utf-8\"")); + //Contruct the header for the schema $schemaElem = new DOMIT_Element('xs:schema'); //Root element <xs:schema *************** *** 1420,1431 **** --- 1452,1475 ---- //Import namespaces to provide access to particular fields from LOM/DC $dcImportNode = new DOMIT_Element('xs:import'); + $dcImportAttr = new DOMIT_Attr('namespace'); $dcImportAttr->nodeValue=$dublinCoreUri; + + $dcImportLoc = new DOMIT_Attr('schemaLocation'); + $dcImportLoc->nodeValue=$dublinCoreLocation; + $dcImportNode->setAttributeNode($dcImportAttr); + $dcImportNode->setAttributeNode($dcImportLoc); $lomImportNode = new DOMIT_Element('xs:import'); + $lomImportAttr = new DOMIT_Attr('namespace'); $lomImportAttr->nodeValue=$learningObjectUri; + + $lomImportLoc = new DOMIT_Attr('schemaLocation'); + $lomImportLoc->nodeValue=$learningObjectLocation; + $lomImportNode->setAttributeNode($lomImportAttr); + $lomImportNode->setAttributeNode($lomImportLoc); $schemaElem->appendChild($dcImportNode); *************** *** 1481,1488 **** $schemaMinOccursAttr = &new DOMIT_Attr('minOccurs'); ! //Assume a default minimum occurrence for the field if (empty($questionField['minoccurs'])) { ! $schemaMinOccursAttr->nodeValue=1; } --- 1525,1532 ---- $schemaMinOccursAttr = &new DOMIT_Attr('minOccurs'); ! //Assume a default minimum occurrence of 0 for the field - doesnt have to crop up if (empty($questionField['minoccurs'])) { ! $schemaMinOccursAttr->nodeValue=0; } *************** *** 1493,1497 **** $schemaMaxOccursAttr = &new DOMIT_Attr('maxOccurs'); ! //Assume a default minimum occurrence for the field if (empty($questionField['maxoccurs'])) { --- 1537,1541 ---- $schemaMaxOccursAttr = &new DOMIT_Attr('maxOccurs'); ! //Assume a default maxmimum occurrence for the field if (empty($questionField['maxoccurs'])) { *************** *** 1627,1630 **** --- 1671,1675 ---- } + $xmlElements[] = $type; //Add 'type' to collection of xml elements $schemaComplexType->appendChild($schemaSequence); $schemaElement->appendChild($schemaComplexType); *************** *** 1637,1641 **** $schemaElementAttr = &new DOMIT_Attr('name'); $schemaElementAttr->nodeValue='question'; ! $schemaElement->setAttributeNode($schemaElementAttr); --- 1682,1687 ---- $schemaElementAttr = &new DOMIT_Attr('name'); $schemaElementAttr->nodeValue='question'; ! $xmlElements[] = 'question'; ! $schemaElement->setAttributeNode($schemaElementAttr); *************** *** 1744,1747 **** --- 1790,1794 ---- $schemaElementAttr = &new DOMIT_Attr('name'); $schemaElementAttr->nodeValue='questionOptions'; + $xmlElements[] = 'questionOptions'; $schemaElement->setAttributeNode($schemaElementAttr); *************** *** 1787,1790 **** --- 1834,1838 ---- $schemaElementAttr = &new DOMIT_Attr('name'); $schemaElementAttr->nodeValue='questionPotResp'; + $xmlElements[] = 'questionPotResp'; $schemaElement->setAttributeNode($schemaElementAttr); *************** *** 1793,1812 **** $schemaSequence = &new DOMIT_Element('xs:sequence'); foreach($stackQuestionPotResp as $arrayKey=>$responsesField) { ! $schemaField = &new DOMIT_Element('xs:element'); ! $schemaFieldAttr = &new DOMIT_Attr('name'); ! $schemaFieldAttr->nodeValue=$arrayKey; ! $schemaTypeAttr = &new DOMIT_Attr('type'); ! $schemaTypeAttr->nodeValue='xs:string'; ! $schemaField->setAttributeNode($schemaFieldAttr); ! $schemaField->setAttributeNode($schemaTypeAttr); ! $schemaSequence->appendChild($schemaField); ! ! /*$schemaMinOccursAttr = &new DOMIT_Attr('minOccurs'); //Assume a default minimum occurrence for the field --- 1841,1879 ---- $schemaSequence = &new DOMIT_Element('xs:sequence'); + $responseBranch = &new DOMIT_Element('xs:element'); + $responseBranchName = &new DOMIT_Attr('name'); + $responseBranchName->nodeValue='true'; + + $responseBranch->setAttributeNode($responseBranchName); + + $responseBranchCopy = &new DOMIT_Element('xs:element'); + $responseBranchCopyName = &new DOMIT_Attr('name'); + $responseBranchCopyName->nodeValue='false'; + + $responseBranchCopy->setAttributeNode($responseBranchCopyName); + + $responseBranchCType = &new DOMIT_Element('xs:complexType'); + $responseBranchSeq = &new DOMIT_Element('xs:sequence'); + + //Global response parameters foreach($stackQuestionPotResp as $arrayKey=>$responsesField) { ! //If the field is not a branched response parameter ! if (!$responsesField['branch']) ! { ! $schemaField = &new DOMIT_Element('xs:element'); ! $schemaFieldAttr = &new DOMIT_Attr('name'); ! $schemaFieldAttr->nodeValue=$arrayKey; ! $schemaTypeAttr = &new DOMIT_Attr('type'); ! $schemaTypeAttr->nodeValue='xs:string'; ! $schemaField->setAttributeNode($schemaFieldAttr); ! $schemaField->setAttributeNode($schemaTypeAttr); ! $schemaSequence->appendChild($schemaField); ! ! /*$schemaMinOccursAttr = &new DOMIT_Attr('minOccurs'); //Assume a default minimum occurrence for the field *************** *** 1820,1830 **** $schemaMinOccursAttr->nodeValue=$questionField['minoccurs']; }*/ } $schemaComplexType->appendChild($schemaSequence); $schemaElement->appendChild($schemaComplexType); $schemaElem->appendChild($schemaElement); ! //4. The 'keyval' type /* <xs:complexType name="keyval"> --- 1887,1987 ---- $schemaMinOccursAttr->nodeValue=$questionField['minoccurs']; }*/ + } + + + //If the field does belong to a response branch. Add to colllection within the true/false elements + else if ($responsesField['branch']) + { + $responseField = &new DOMIT_Element('xs:element'); + + $responseFieldAttr = &new DOMIT_Attr('name'); + $responseFieldAttr->nodeValue=$arrayKey; + + $responseTypeAttr = &new DOMIT_Attr('type'); + $responseTypeAttr->nodeValue='xs:string'; + + $responseField->setAttributeNode($responseFieldAttr); + $responseField->setAttributeNode($responseTypeAttr); + + $responseBranchSeq->appendChild($responseField); + } } + $responseBranchCType->appendChild($responseBranchSeq); + $responseBranch->appendChild($responseBranchCType); + $responseBranchCopy->appendChild($responseBranchCType); + + //Make copy of response branch, then change name attribute to 'false' - saves processing + //$responseBranchCopy = new DOMIT_Element(''); + //$responseBranchCopy = $responseBranch; + //$responseBranchCopy->setAttribute('name','false'); + + $schemaSequence->appendChild($responseBranch); + $schemaSequence->appendChild($responseBranchCopy); + $schemaComplexType->appendChild($schemaSequence); $schemaElement->appendChild($schemaComplexType); + //$schemaElement->appendChild($responseBranch); + //$schemaElement->appendChild($responseBranchCopy); $schemaElem->appendChild($schemaElement); ! //4. The keyval type - call function ! $schemaKeyValElement = stack_xml_create_schema_keyval_type(); ! ! $schemaElem->appendChild($schemaKeyValElement); ! ! //5. Now we must link these types to the head element - the 'AssessmentItem' ! //Iterate through each of the types written into the schema - xmlElement ! /*<xs:element name="AssessmentItem"> ! <xs:complexType> ! <xs:all> ! <xs:element ref="dublincore" /> ! <xs:element ref="lom" /> ! <xs:element ref="stack" /> ! <xs:element ref="question" /> ! <xs:element ref="questionOptions" /> ! <xs:element ref="questionPotResp" /> ! </xs:all> ! </xs:complexType> ! </xs:element> ! */ ! $schemaElement = &new DOMIT_Element('xs:element'); ! ! $schemaElementAttr = &new DOMIT_Attr('name'); ! $schemaElementAttr->nodeValue='assessmentItem'; ! ! $schemaElement->setAttributeNode($schemaElementAttr); ! ! $schemaComplexType = &new DOMIT_Element('xs:complexType'); ! ! $schemaAllElem = &new DOMIT_Element('xs:all'); ! ! foreach($xmlElements as $xmlElement) ! { ! $schemaField = &new DOMIT_Element('xs:element'); ! ! $schemaFieldAttr = &new DOMIT_Attr('ref'); ! $schemaFieldAttr->nodeValue=$xmlElement; ! ! $schemaField->setAttributeNode($schemaFieldAttr); ! ! $schemaAllElem->appendChild($schemaField); ! } ! ! //5.1. We must append a version element onto the schema, within the AssessmentItem element ! $schemaVersionElement = stack_xml_create_schema_version(); ! ! $schemaComplexType->appendChild($schemaAllElem); ! $schemaComplexType->appendChild($schemaVersionElement); ! $schemaElement->appendChild($schemaComplexType); ! $schemaElem->appendChild($schemaElement); ! ! //Append root schema node onto DOM object and save ! $dom->appendChild($schemaElem); ! print_r("gone in here"); ! $dom->saveXML('schemas/test.xsd',true); ! } ! ! //4. The 'keyval' type /* <xs:complexType name="keyval"> *************** *** 1835,1842 **** </xs:complexType> */ $schemaComplexType = &new DOMIT_Element('xs:complexType'); $schemaCTypeAttr = &new DOMIT_Attr('name'); ! $schemaCTypeAttr->nodeValue $schemaSequence = &new DOMIT_Element('xs:sequence'); --- 1992,2010 ---- </xs:complexType> */ + + //Creates an XML field, taking in the number of occurences: default to 0 + function stack_xml_create_field($name, $minOccurs,$maxOccurs) + { + //Return an xml element which can simply be appended + } + + function stack_xml_create_schema_keyval_type() + { $schemaComplexType = &new DOMIT_Element('xs:complexType'); $schemaCTypeAttr = &new DOMIT_Attr('name'); ! $schemaCTypeAttr->nodeValue='keyval'; ! $schemaComplexType->setAttributeNode($schemaCTypeAttr); ! $schemaSequence = &new DOMIT_Element('xs:sequence'); *************** *** 1871,1964 **** //Append onto main schema element $schemaComplexType->appendChild($schemaSequence); - $schemaElem->appendChild($schemaComplexType); - - //5. Now we must link these types to the head element - the 'Question' ! ! /* //Export element to XML ! $schemaField = new DOMIT_Element('xs:element'); ! $schemaFieldAttr ! ! ! //Parse only metadata fields ! if (!empty($questionField['type']) && ($questionField['type']=='meta')) { ! ! //Check metatag contains something - otherwise we default to STACK namespace ! if (!empty($questionField['metatype']) && $array_value_exists($types, $questionField['metatype')) ! { ! $types[] = $questionField['metatype']; ! } ! } ! } ! } ! ! ! //If of any other type except meta and other ! else ! { ! if(!empty($questionField['doc'])) { ! $xml.=stack_schema_write_element_document($arrayKey,$questionField['mysql'],$questionField['doc']); ! } ! ! else { ! $xml.=stack_schema_write_element($arrayKey,$questionField['mysql']); ! } ! ! } ! } ! }*/ ! ! $dom->appendChild($schemaElem); ! $dom->saveXML('test.xsd'); ! ! //$xml = ""; ! ! /*//Create a sequence of metadata tags ! $xml.='<xs:sequence>'; ! ! //An assessment item consists of a single question, a number of reponses, and a set of options ! foreach($stackQuestion as $arrayKey=>$questionField) //Iterate through sub array of each array object ! { ! //We dont want to parse metadata, but we do with other fields ! if (!empty($questionField['type']) && array_value_exists(&) { ! ! //Other fields are arrays of other structures, such as $stackOptions and $stackQuestionPotResp ! if($questionField['type']=='other') ! { ! //Check questionfieldkey is either options or potentioal responses, if not echo a warning to the developer ! //foreach($arrayKey as ! } ! ! //If of any other type except meta and other ! else ! { ! if(!empty($questionField['doc'])) { ! $xml.=stack_schema_write_element_document($arrayKey,$questionField['mysql'],$questionField['doc']); ! } ! ! else { ! $xml.=stack_schema_write_element($arrayKey,$questionField['mysql']); ! } ! ! } ! } ! } ! ! //Terminate a sequence of metadata tags ! $xml.='</xs:sequence>'; ! ! //We must now tag the 'metadata' tag with a version attribute ! $xml.= stack_schema_write_attribute('version', true); ! ! return $xml; ! ! ! */ ! } //Takes in a 1D array and searches to see if a particular item occurs in the array function array_value_exists(&$array, $value) --- 2039,2081 ---- //Append onto main schema element $schemaComplexType->appendChild($schemaSequence); ! return $schemaComplexType; ! } ! //Creates a version element for putting onto the schema ! function stack_xml_create_schema_version() ! { ! $schemaVersionElement = &new DOMIT_Element('xs:attribute'); ! $schemaVersionElementNameAttr = &new DOMIT_Attr('name'); ! $schemaVersionElementNameAttr->nodeValue='version'; + $schemaVersionUseAttr = &new DOMIT_Attr('use'); + $schemaVersionUseAttr->nodeValue='required'; + + $schemaVersionElement->setAttributeNode($schemaVersionElementNameAttr); + $schemaVersionElement->setAttributeNode($schemaVersionUseAttr); + $schemaSimpleType = &new DOMIT_Element('xs:simpleType'); + $schemaRestrictionType = &new DOMIT_Element('xs:restriction'); ! $schemaRestrictionTypeBaseAttr = &new DOMIT_Attr('base'); ! $schemaRestrictionTypeBaseAttr->nodeValue='xs:string'; ! ! $schemaRestrictionType->setAttributeNode($schemaRestrictionTypeBaseAttr); ! ! $schemaPatternType = &new DOMIT_Element('xs:pattern'); ! ! $schemaPatternTypeAttr = &new DOMIT_Attr('value'); ! $schemaPatternTypeAttr->nodeValue='[1-9]+[0-9]*\.[0-9]+'; ! ! $schemaPatternType->setAttributeNode($schemaPatternTypeAttr); ! ! //Construct version entity ! $schemaRestrictionType->appendChild($schemaPatternType); ! $schemaSimpleType->appendChild($schemaRestrictionType); ! $schemaVersionElement->appendChild($schemaSimpleType); + return $schemaVersionElement; + } //Takes in a 1D array and searches to see if a particular item occurs in the array function array_value_exists(&$array, $value) *************** *** 2164,2168 **** } ! stack_xml_create_question_schema('',''); echo("Saved schema"); ?> --- 2281,2285 ---- } ! stack_xml_create_question_schema(); echo("Saved schema"); ?> Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.30.2.2 retrieving revision 1.30.2.3 diff -C2 -d -r1.30.2.2 -r1.30.2.3 *** stackQuestion.php 1 Aug 2005 21:56:34 -0000 1.30.2.2 --- stackQuestion.php 2 Aug 2005 16:00:26 -0000 1.30.2.3 *************** *** 480,484 **** $stackQuestion['questionKeywords']['metatag']='keyword'; ! $stackQuestion['questionKeywords']['metatype']='dublincore'; // 'Body'; --- 480,484 ---- $stackQuestion['questionKeywords']['metatag']='keyword'; ! $stackQuestion['questionKeywords']['metatype']='lom'; // 'Body'; *************** *** 596,600 **** $stackQuestion['questionLearningContext']['mysql']='TINYTEXT'; ! $stackQuestion['questionLearningContext']['metatag']='learningcontext'; $stackQuestion['questionLearningContext']['metatype']='lom'; --- 596,600 ---- $stackQuestion['questionLearningContext']['mysql']='TINYTEXT'; ! $stackQuestion['questionLearningContext']['metatag']='context'; $stackQuestion['questionLearningContext']['metatype']='lom'; *************** *** 836,856 **** //////////////////////////////////// ! ! // 'Expression 1: SAns'; $stackQuestionPotResp['SAns']['type']='casstring'; // 'Expression 2: TAns'; $stackQuestionPotResp['TAns']['type']='casstring'; // 'Answer test'; $stackQuestionPotResp['AnsTest']['type']='option'; // 'Answer test options'; $stackQuestionPotResp['AnsTestOpt']['type']='option'; // The following fields are indented within 'true' or 'false' branches --- 836,860 ---- //////////////////////////////////// ! // <PDK>Branch field put in for autodectection of branch/global reponse parameters within schema writing // 'Expression 1: SAns'; $stackQuestionPotResp['SAns']['type']='casstring'; + $stackQuestionPotResp['SAns']['branch']=FALSE; + // 'Expression 2: TAns'; $stackQuestionPotResp['TAns']['type']='casstring'; + $stackQuestionPotResp['TAns']['branch']=FALSE; // 'Answer test'; $stackQuestionPotResp['AnsTest']['type']='option'; + $stackQuestionPotResp['AnsTest']['branch']=FALSE; // 'Answer test options'; $stackQuestionPotResp['AnsTestOpt']['type']='option'; + $stackQuestionPotResp['AnsTestOpt']['branch']=FALSE; // The following fields are indented within 'true' or 'false' branches *************** *** 859,882 **** --- 863,892 ---- $stackQuestionPotResp['RawMarkMod']['type']='option'; + $stackQuestionPotResp['RawMarkMod']['branch']=TRUE; // 'Mark modifier'; $stackQuestionPotResp['RawMark']['type']='option'; + $stackQuestionPotResp['RawMark']['branch']=TRUE; // 'Penalty'; $stackQuestionPotResp['Penalty']['type']='option'; + $stackQuestionPotResp['Penalty']['branch']=TRUE; // 'Feedback'; $stackQuestionPotResp['FeedBack']['type']='castext'; + $stackQuestionPotResp['FeedBack']['branch']=TRUE; // Answer note'; $stackQuestionPotResp['AnswerNote']['type']='string'; + $stackQuestionPotResp['AnswerNote']['branch']=TRUE; // 'Apply later tests'; $stackQuestionPotResp['ApLat']['type']='string'; + $stackQuestionPotResp['ApLat']['branch']=TRUE; |