From: pkiddie <pk...@us...> - 2005-07-18 16:23:35
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6294/scripts Modified Files: stackQuestion.php stackXML.php Log Message: Tweaks to stackXML Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** stackXML.php 18 Jul 2005 14:32:14 -0000 1.10 --- stackXML.php 18 Jul 2005 16:23:13 -0000 1.11 *************** *** 243,249 **** function stack_schema_write_metadata($directory) { ! //takethe stackQuestion and extract all the current metadata tags, putting them into a schema ! //file extension .xsd represents schema ! $schema_file_name='stack_metadata.xsd'; //create file used for writing $xml_file_handle = fopen($directory.$schema_file_name,"w"); --- 243,249 ---- function stack_schema_write_metadata($directory) { ! global $stackQuestion; ! ! $schema_file_name='stack_question_metadata-'.$stackQuestion['version'].'.xsd'; //File name of schema has version number of stackQuestion clearly identified //create file used for writing $xml_file_handle = fopen($directory.$schema_file_name,"w"); *************** *** 256,261 **** else { ! //Write the XML schema header - same for all XML schemas ! $xml = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">'. "\n". '<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>'. --- 256,262 ---- else { ! //Write the XML schema header - same for all XML schemas - with version number. ! //XML metadata files which validate against this schema will also have a version number ! $xml = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="'.$stackQuestion['version'].'">'. "\n". '<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>'. *************** *** 287,292 **** { return "<xs:element name=".'"'.$rootElement.'">'. ! '<xs:complexType>'. ! '<xs:sequence>'; } --- 288,292 ---- { return "<xs:element name=".'"'.$rootElement.'">'. ! '<xs:complexType>'; } *************** *** 298,306 **** function stack_schema_escape_root() { ! return '</xs:sequence>'. ! '</xs:complexType>'. ! "</xs:element>"; } - /** * Writes the current stackQuestion metadata structure to an XML string --- 298,304 ---- function stack_schema_escape_root() { ! return '</xs:complexType>'. ! '</xs:element>'; } /** * Writes the current stackQuestion metadata structure to an XML string *************** *** 316,326 **** function stack_schema_create_metadata() { ! global $sqlToSchemaMapping,$stackQuestion; //use definitive stackQuestion data structure ! include('../stackstd.php'); ! // HACK for now. $options = stack_options_set(array()); ! $filename = stack_lang_filename($options,'doc/en_doc.php'); //Include documentation to document the tags if it is available include($filename); --- 314,323 ---- function stack_schema_create_metadata() { ! global $sqlToSchemaMapping,$stackQuestion; //use definitive stackQuestion data structure ! include('../stackstd.php'); $options = stack_options_set(array()); ! $filename = stack_lang_filename($options,'doc/en_doc.php'); //Include documentation to document fields if it is available include($filename); *************** *** 337,340 **** --- 334,340 ---- } + //Create a sequence of metadata tags + $xml.='<xs:sequence>'; + foreach($stackQuestion as $arrayKey=>$questionField) //Iterate through sub array of each array object { *************** *** 374,378 **** if (!empty($questionField['doc'])) { $xml.=stack_schema_write_element_document_enum_type($questionField['metatag'],strtolower($questionField['metatag']),$questionField['doc']); - } --- 374,377 ---- *************** *** 389,392 **** --- 388,397 ---- } } + + //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; *************** *** 394,397 **** --- 399,458 ---- /** + * Constructs an XML schema attribute + * Example: <xs:attribute name="version" use="required"> + * <xs:simpleType> + * <xs:restriction base="xs:string"> + * <xs:pattern value="[1-9]+[0-9]*\.[0-9]+" /> + * </xs:restriction> + * </xs:simpleType> + * </xs:attribute> + * + * + * @param string $attribName The name of the attribute to be written to XML schema + * @param bool $isRequired Flag indicating whether attribute is mandatory + * @return string XML string representing schema attribute + */ + function stack_schema_write_attribute($attribName, $isRequired) + { + $xml=""; + + if ($isRequired) + { + $xml='<xs:attribute name = "'.$attribName.'" use = "required">'. + stack_schema_write_version_simpletype(). + '</xs:attribute>'; + + } + + else + { + $xml='<xs:attribute name = "'.$attribName.'" use = "optional">'. + stack_schema_write_version_simpletype(). + '</xs:attribute>'; + } + + return $xml; + } + + /** + * Writes a 'version' XML string based on a schema attribute + * + * @return string a simpleType encapsulating version convention: M.N, where M is major version, N is minor + */ + function stack_schema_write_version_simpletype() + { + $xml=""; + $versionFilter="[1-9]+[0-9]*\.[0-9]+"; + + $xml = '<xs:simpleType> + <xs:restriction base = "xs:string"> + <xs:pattern value = "'.$versionFilter.'"/> + </xs:restriction> + </xs:simpleType>'; + + return $xml; + } + + /** * Writes a given field within stackQuestion as a schema element, with a representative XML schema datatype * *************** *** 598,602 **** else { ! $xml.=stack_schema_create_simpletype($questionField['metatag'],$questionField['values']); } } --- 659,663 ---- else { ! $xml.=stack_schema_create_simpletype(strtolower($questionField['metatag']),$questionField['values']); } } Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.28 retrieving revision 1.29 diff -C2 -d -r1.28 -r1.29 *** stackQuestion.php 18 Jul 2005 14:32:13 -0000 1.28 --- stackQuestion.php 18 Jul 2005 16:23:13 -0000 1.29 *************** *** 351,355 **** //Versioning required to check whether schema is up to date ! $stackQuestion['version']=1; //////////////////////////////////// --- 351,357 ---- //Versioning required to check whether schema is up to date ! //Where version number has form M.N where M is major version number ! // N is minor version number ! $stackQuestion['version']='1.0'; //////////////////////////////////// |