XML Data Access via MOODLE Platform

With the resources provided by communication technologies, E-learning has been employed in multiple universities, as well as in wide range of training centers and schools. This book presents a structured collection of chapters, dealing with the subject and stressing the importance of E-learning. It shows the evolution of E-learning, with discussion about tools, methodologies, improvements and new possibilities for long-distance learning. The book is divided into three sections and their respective chapters refer to three macro areas. The first section of the book covers methodologies and tools applied for E-learning, considering collaborative methodologies and specific environments. The second section is about E-learning assessment, highlighting studies about E-learning features and evaluations for different methodologies. The last section deals with the new developments in E-learning, emphasizing subjects like knowledge building in virtual environments, new proposals for architectures in tutoring systems, and case studies.


The MOODLE platform
IT development, the more and more popular access to the Internet and variety of tools enabling using it in the field of teaching (Nedeva, 2005), encourage many educational institutions and companies to expand their offers with e-learning courses (Daku, 2009, Dobrzański&Brom&Brytan, 2007. Owing to that, quicker access to knowledge and learning costs reduction can be achieved. Course materials can be studied by the employees or students at a convenient time and place, which gives them a chance to equalize possibilities of getting an education. However, when using the available e-learning tools, two problems are observable.  So far, usage of e-learning platforms is limited to theory presentation and exchange of teaching materials, whereas, in some knowledge branches -especially in the field of technical science -teaching practical usage of theory, experience achieved in real environments and learning from one's own mistakes play an important role. Current functionality of e-learning platforms does not provide such possibilities.  Second problem results from asynchronous type of learner-teacher communication, which makes both sides dependent on their mutual activity. Solutions of complex problems are usually more extensive than just a yes/no answer. It should be taken into consideration that very often many aspects of the solution should be analyzed, which can have a massive effect on delays in remote communication. Thus, an automatic estimation of solutions inconvenience should be introduced. Dealing with the aforementioned problems will enrich and make teaching process more effective on various levels of education. What is more, in many cases, capabilities of tools, supporting e-learning are higher than only knowledge presentation and make elimination of described inconveniences possible. Because, one of the most popular and free environments for e-learning is Modular Object-Oriented Dynamic Learning Environment [MOODLE] (MOODLE Home Page -Statistics, Braccini&Silvestri&Za&D'Atri, 2009), it was used in the research in order to extend it with the new mechanisms. MOODLE course management allows teachers to build their courses in an optimal way for their learners and subject matter. The platform capabilities include many different mechanisms -i.e. activities, giving trainees possibility to test and to resolve given problems in practice and passive resources, allowing the knowledge presentation. The Open Source distributed MOODLE environment, has the specific (i.e. modular) organization. Besides, it cooperates with a database server -one of the following can be used: MySQL, PostgreSQL or MS SQL Server (MOODLE Home Page -About MOODLE). This features caused, it was very suitable tool for introducing new mechanisms to a group of already existing activities. Due to the fact, in previous papers (Harężlak&Werner, 2009;Harężlak&Werner, 2010), the MOODLE module structure was explained in details, now only the key issues will be described. After installing the whole environment (i.e. Apache Server, PHP and chosen database server), all MOODLE courses modules, such as: chat, forum, glossary, lesson, quiz, etc, are placed in one folder /www/mod of WAMP server installation path 1 . Every module has its separate folder of a corresponding name and the similar structure. The most important -and obligatory in each folder -files, are: mod_form.php and view.php. First file is responsible for a contents of page seen by a teacher during editing an activity, while second one -for contents of page seen by course participants during executing an activity. Thus, the new module implementation is in practice reduced to creating a new folder with a known structure, and to providing the desired functionality of component files by the PHP or Java Script coding. Taking the important role of XML language in the exchange of a wide variety of data into consideration, the new custom XML mechanisms were developed in order to make the completion of educational tasks possible. Therefore tasks (activities) with a different exercise level of difficulty were prepared in a module. Among them, two groups can be enumerated. First of them consists of simple operations on an XML file:  creating a simple XML document,  analysing of an XML file content,  inserting a single row of data and loading data from an XML file. In the second one, more complex tasks, regarding database mechanisms for XML data management, are considered:  designing and creating database structures, dedicated to XML data collecting,  building XML schemas and assigning them to the database structures,  retrieving relational data as XML and querying XML data with usage of advanced methods. The chapter will present novel mechanisms guaranteeing comprehensive, interactive XML language learning.

Sample XML data structure
The analysis of the proposed solutions will be conducted on the basis of the example presented below. The XML document instance that describes titles, authors and supervisors of students thesis (Master and BA) in the Polish universities, will be taken into consideration. Let's assume, the task formulated in XML module by the tutor, is: Write the well-formed instance of the XML document for the universities students' thesis data. First, data about the name of the university should be stored. Then -subsequently -for each student after defence, the student register number, the type (Master or BA) and title of thesis, the year of defence, finally, the name of student's promoter and his titles should be placed. Additional requirements: use the tag <List> for the root element. Don't use tag attributes -only Element components. All data about the Master or BA thesis of the specified student should be described in 1 element. The description about each kind of a student's thesis should be contained in separate elements. The solution should contain an example data for 2 students from different universities. Suppose, first student is after Master and BA defence in Silesian Technical University, while second -only after BA in AGH University. There are a lot of possibilities to formulate the given XML document instance for the given task. Two sample alternative XML documents of given requirements, where the names of the tags are not significantly different (University vs. UnivName, TypeBA vs. BA, etc.), are shown in fig. 1.

Defining an XML document
As it was presented in the Introduction, XML documents can be utilized in many areas of life, but to be useful, they have to be prepared accordingly with a given structure, comprehensible for every interested part. Therefore, the most basic skills needed for the XML data management are an ability to formulate and analyze well-formed XML documents. Their teaching is supposed to be conducted in two directions. On one hand, the knowledge concerning rules of creating XML documents should be presented. On the other hand, there is a need to take care of gaining an experience in this field. Basis for obtaining such experience is an individual, practical usage of theory supported by feedback regarding types and places of made mistakes. Due to that fact, functionality for XML document defining was designed for the MOODLE platform (Fig. 3), in which verifying of a document instance correctness was the most important problem to solve. It was accomplished with usage of both the MOODLE platform and database objects. Two groups of tables were introduced. The first one is dedicated to the teachers and serves as a container for descriptions of proper documents structures. The second one is indented to collect course participants' solutions. Validation of this solution is performed by the comparison of the contents of both groups. The appropriate functions are responsible for realization of this process.

Defining a structure of an XML document template
In the first research phase there was assumed that a teacher preparing tasks to be solved by course participants knows mechanism of the MOODLE platform well and does not have to know issues concerning computer science. So, mechanisms, introduced into this environment, had to be prepared in a way enabling teacher to use his/her skills. The initial step in the research was to adjust a teacher's window to new functionality, which is XML document structure management. For this purpose, the mod_form.php file for a new activity, called XML, was modified (Fig. 3). Changes regarded both its construction and logic, it contained. Structure of the window was extended with a few elements. The most important one is the htmleditor named xml_entry (Fig. 4), which is designed to be filled with an XML document template structure. Because content of this element will be different for various tasks, the identifier of a task should be entered as well (task_number, Fig. 5).
$mform->addElement('htmleditor','xml_entry',get_string('XML entry','xml')); $mform->addElement('text','task_number',get_string('task number','xml')); The provided XML template, for further use, has to be inserted into the database. Therefore, the validation function, which is run during the process of saving the newly defined activity, was equipped with required logic. Details of a database and credentials can to be provided by a teacher in next four fields ( Fig. 6): or can be prepared by a module administrator with usage of a setDefault function, as is presented below: This database, as mentioned above, must possess a special Tag_templates table, in which each tag from a template structure and its level in tags tree are stored in one row. Additionally, this information is complemented by the number of the task being created. However, before it is possible, XML template must be divided into substrings -one for each tag. This operation is also performed by the logic of the validation function. Unfortunately, usage of hmleditor element entailed problems regarding recognizing limiters of tags -e.g. < and > characters. They belong to a set of special symbols of HTML language and are represented by strings in form of &lt; and &gt; respectively. In consequence, obtaining string representing a tag must be preceded by extracting these chars. This problem can be avoided by using textarea elements: $mform->addElement('textarea','xml_entry',get_string('XML entry','xml')); $mform->addElement('textarea','synonyms',get_string('Synonyms','xml'));

www.intechopen.com
During the process of XML template transformation a level of a tag is calculated as well. For example, if the aforementioned sample structure was taken into consideration, the result of acting of the validation function would consist of elements presented in the Table 1 The Validation function is also responsible for checking contents of Tag_template table. If rows of another template for the considered task are found, they are replaced by a newly defined set.

Validating solution correctness
When the whole process of defining XML document template is finished, new activity can be utilized by course participants in the same way as all predefined in the MOODLE platform objects and is accessible in a list of participant's tasks. Window of the XML activity includes tree elements ( Fig. 7): task contents, text area for its solution and Check structure button, which starts a procedure of verifying a correctness of a solution. This procedure, included in logic of the view.php file, is based on data inserted to the Tag_templates table and similarly, begins with splitting solution into substrings. Because a base for this partitioning is the symbol of a new line, the requirement ending each tag and value by this character has to be fulfilled. For each substring a level is calculated, which, subsequently, is compared with the level defined for a related tag in a template. In case of detecting a difference participant receives an appropriate message ( Fig. 8). At the end of the www.intechopen.com process, an existence of a corresponding opening and closing tags is checked. A proper solution is acknowledged with a suitable notification (Fig. 9).  Independently, every analyzed element is remembered in Solutions table. A row of this table  includes task number, tag, its level in a structure defined by a participant and user identifier assigned to her/him. Owing to that, a teacher is able to analyze the result of a participant's work. Additionally, a new row, containing data on task and a participant solving it, is added to Grades table. If a solution is acceptable, the passed column is checked in this record. In other case column named attempt is incremented. The number of possible attempts is defined by a teacher in a task configuration window, through the additional element introduced into the mod_form.php file (Fig. 10):

The synonyms
Analysis of tasks' solutions can indicate that course participant prepared a good solution of a task, but used different tags from those defined in a template. XML elements must follow a few naming rules (e.g. names cannot contain spaces), but any name can be used, because no words are reserved. Therefore mechanisms for defining synonyms were developed. Again, the mod_form.php file was utilized. The set of elements defining teacher's window was extended with one more html editor for synonyms providing (Fig. 11).
$mform->addElement('htmleditor','synonyms',get_string('synonyms', 'xml')); A synonym format is specified to facilitate an analysis of entered words. Each tag with additional words should be surrounded by square brackets: "[" ,"]". First word in that scope should be a tag ended by ":" character. After that, synonyms for a given tag, separated by a space, could be placed. Once more, example of the universities students' thesis data will be taken into consideration. To define alternative words for UnivName, Student and Master tags, teacher should prepare following script: Such script has to be placed within the synonyms element when task is being defined or edited. Subsequently, it is analyzed by the validation function, in which the operation of additional HTML symbols removal comes first. Next, each row of the script is being prepared to be loaded into the database. Two versions of database structures for storing synonyms were analyzed. On one hand, they can be inserted into one column and treated as one text. On the other, they can be spread into two tables -one being a kind of synonyms dictionary with one record per synonym and second one associating tags with their synonyms. This solution allows for writing a synonym once and then map it to many tags, but requires more tables' joins than in the first case. However, both of them were implemented and comparing their effectiveness is planned in the further research. www.intechopen.com The simplified algorithm of the procedure for validating participant's solution correctness, which takes mechanism of synonyms management into account, is shown in the listing 1. Thanks to the developed synonyms management functionality, mechanisms for validation of participants task solutions become more flexible. In case when function, which implements this functionality, discovers differences in template and student tags, it can still consider a given solution as a correct one (Fig. 12) if it finds a tag, provided by a student, in the synonyms table/tables. Moreover, in case of a need, a once-defined set of synonyms can be extended by usage of the mechanism described in subsequent parts of the chapter.

Creation of an educational path
Process of acquiring necessary skills can develop at a different speed for different course participants. Sometimes presented knowledge requires only few tasks to be done, in other cases it should be practiced many times. For this reason, the simple mechanism, determining the number and difficulty of tasks to be solved by a given participant, depending on his/her current progress, was proposed in the developed activity. In the present stage of the research, it is based on a number of attempts allowed to obtain a proper solution of a task. This number should be specified by a teacher during defining the task (attempts_number in mod_form.php file -as it was presented in the fig. 10), but if it is omitted, the default value is taken into account. This value is calculated for a participant accordingly with its activity (column Attempt in the Grade table) and is used by the logic of the view.php file to check how he/she dealt with a given task. Among cases being considered by this logic, the following can be enumerated. 1. Course participant has not attempted to solve a task yet -as a result, task window is opened for a task defined by a teacher. 2. Course participant has already solved a task -an appropriate message and three buttons are displayed; one for task redoing, second for solving a new task, with the same difficulty level and third for cancelling the action (Fig. 13). Fig. 13. View of a participant's window with a given task already solved.
3. Course participant undertakes the next attempt to solve a task, which previously was not solved correctly, but an attempt number is less than the highest acceptable (e.g. less than defined by a teacher) -in such situation, acting of the view.php file logic is the same as in the first case. 4. Course participant undertakes the next try to solve a task but an attempt number is greater than acceptable -discovering such situation results in displaying a message, which includes task number that should be completed before a next attempt to the current one occurs (Fig. 14). 5. Course participant gets back to solving a task, because he/she didn't manage to solve one of the subsequent tasks. In such case, the subject of the task should be changed, but its difficulty should stay on the same level. Activity of this kind entails creating a new template solution and preparing a new set of synonyms. That process can be automated www.intechopen.com by usage of text files with standardized names. Their responsibility is to define new contents enabling the configuration of the task in accordance with the attempt number. The basic part of the file name (so called prefix), together with its path, should be provided by a teacher, in task definition window through file_name element (Fig. 15).
Its content is then used for constructing full files names. Among them there are:  prefix_cont_attemp_number.txt -containing task subject for a given attempt number,  prefix_temp_attemp_number.txt -containing template of the solution for a given attempt number,  prefix_synonym_attemp_number.txt -containing synonyms for a given attempt number, prepared in accordance with the aforementioned format. Let's assume that a course participant did not manage to solve the task marked by number 5, because he/she exceeded number of allowed attempts. According to the proposed rules he/she was directed to get back to task number 4. In the first attempt, it is defined to solve the problem presented in Sample XML data structure part, but now the content of the task have to be changed. Let's assume once again that a file prefix provided by a teacher has the same value as it is shown in the fig. 15. This means that files used for the second attempt of the task will be searched for in c:\xml folder with following conditions:  c:\xml\task4_cont_2.txt -for a new task content,  c:\xml\task4_temp_2.txt -for a new task solution template,  c:\xml\task4_synonym_2.txt -for the new task synonyms. In case one of these files cannot be found, the first attempt configuration is used. Simplified algorithm ensuring the described functionality is presented in the listing 2. The basic structure of teacher's window including all described elements is presented in the fig. 16. Fig. 16. The teacher's window with all described elements.

Advanced mechanisms for the XML activity
The basic functionality of XML activity was tested in terms of its usability. The results of tests indicated the possibilities of further e-learning platform extension. One of them regarded the possibility of the earlier defined set of synonyms extension. Besides, they concerned more advanced XML language issues, directed to the group of participants being at a higher education level. Therefore, the suitable mechanisms for these inconveniences were proposed.

The synonym block
Another proposal to solve the difficulty of XML tags discrepancy is to use a specially implemented Synonym block. This mechanism provides the e-learning platform with the functionality for defining words and their synonyms, as it is shown in fig. 17. There were several reasons for the choice of this type of the MOODLE environment component. The main one was the possibility of adding this kind of object to any module and any course, and, hence, achieving an opportunity to its later usage in other than the www.intechopen.com XML modules. The SQL modules that were developed in the previous research (Harężlak&Werner, 2010) can be a good example of such situation. Fig. 17. The Synonym block.
In that case, the synonym block might be useful in situations, when the schema of a database queried by learners by the usage of SQL module, would change. Then, the typical action performed by a course trainer, would be to rewrite all query tasks (i.e. SQL activities) added to the topic previously and to change the names of the altered columns to a new ones. Whereas, giving the teachers the ability to use the synonym block element, would eliminate this disadvantage. In order to define a new block, the /blocks folder of the MOODLE home directory was changed. As it was mentioned before, the MOODLE software has the modular structure and all its units have similar construction. The same applies to the block element. In practice, in order to define a new synonym block, a new subfolder with the name corresponding to the name of being defined block, with a known set of PHP and HTML files is created. The chosen, mandatory, elements of /synonym folder, are listed in Besides, there are a few HTML files that provide block class, in /synonym subfolder with specific -instance or global level -configuration.
The most important file is the block_synonym.php, where -inter alia -two Web links, referencing to separate PHP files, providing the desired functionality, are specified: $this->content->items[] = '<a href="word.php">Store new word</a>'; $this->content->items[] = '<a href="synonym.php">Store synonym</a>'; Thus, the major modifications of the new block functionality were made in above mentioned files. It is worth emphasizing that these files are located both -in MOODLE home directory and its /course subfolder. Such duplication was necessary to make files accessible for MOODLE users both -at the site, and the course, levels (Fig. 18). New added data -i.e. word itself, word id, annotation and the number of course, the word is defined for is inserted into described earlier synonyms table. The last attribute was intended to enable the word definition only to the selected course that -consequently -reduces the number of searched table rows. New rows are inserted to these table by the use of the especially prepared files -word.php and synonym.php ones. The existence of two separate PHP files causes that in an independent manner -i.e. not necessarily at the same time -words and their synonyms can be defined. The result of the word.php file acting is presented in fig. 19.

DTD documents and XML schema
As it was shown, the validity of XML document can be checked by a lexical analyzer. But in terms of the W3C organization (XML Essentials) valid XML document is a well formed XML document, which also conforms to the rules of a Document Type Definition (DTD) or by its successor -XML Schema.
www.intechopen.com The DTD may be declared inside the XML file (then it should be wrapped in a DOCTYPE definition) or in an external file (then, XML file should be assigned to the DTD definition by <!DOCTYPE root-element SYSTEM "DTDfilename"> element). There is the possibility to extend MOODLE platform with required DTD or XML Schema validation functionality (Webmaster Tutorial -PHP Tutorials), however such validators are also available on-line. As an example, http://www.w3schools.com/xml/xml_validator.asp web page is presented in fig. 20. In addition to XML instance against DTD/XML Schema validation, another important problem was solved in the described XML module. In order to provide mechanisms for comprehensive study of the rules regarding constructing of DTD and XML Schema documents, the suitable algorithms were implemented.
For example, one of the module tasks is to study the sample XML instance, written in a task body and correct given DTD document to fit the specified XML. The mechanism which had to be implemented in the MOODLE platform to check the coincidence of learners' responses with the "model" answer defined by a teacher, was coded in PHP by the usage of auxiliary files.
To grade the correctness of trainee solution (Fig. 21), the sample (i.e. accurate), well-formed, DTD document defined by a teacher is uploaded into a supplementary text file, while the sent answer -into the second temporary text file. Both files are stored in the MOODLE backend server. Because of the fact, a lot of course participants can execute the task at the same time, the temporary file name generated for a particular MOODLE user solution is dynamically composed in a following manner: XML_UserId_ModuleId_TaskNo.txt.
Additionally, to avoid the situation, the numerous spaces will influence the solutions discrepancy, the undue spaces and whitespaces are eliminated from sent answer by the use of regular expressions in form of preg_replace("@\s+@"," ",$file). Generally, the whole algorithm is as follows: Although the XML Schema defining rules differ from the DTD ones, the problems that had to be solved by providing the MOODLE environment with adequate mechanisms were similar. But it must be emphasized, that XML module tasks referring to XML Schemas play another, crucial, role in the topic of storing XML in relational database. Thus, numerous of the new XML functionalities were formulated with regard to a database used in this scope.

XML usage in relational databases
Nowadays, a lot of relational databases -e.g. Oracle and MS SQL Server -provide XML Schema support for the numerous purposes. Validation of the XML documents against registered XML Schema definitions is one of them. As a part of the XML Schema registration process, a database automatically creates the storage for a particular set of XML documents, based on the information provided by the schema. If the document fits to the schema, it is shredded into relational data conforming to the underlying relational table. In described XML activity, the schema registration functionality was introduced. To enable participants the registration of their own XML schemas, suitable PHP script was added to a view.php file. In this type of tasks, the Execute button is used to perform the requested action, as it is shown in fig. 22. In fact, the registration process involves an appropriate built-in procedure. For example in Oracle database repository it was DBMS_XMLSCHEMA.RegisterSchema procedure. Consequently, in the view.php file, the learner schema stored in a string variable, is only The schema registration is only the first step to enable storing the XML data in a relational database. Next, it can be, for example, schema-based table creation, as shown in the following example: CREATE or posting a schema-based document to be inserted into a schema-based XMLType view. In this case, the database system checks whether the XML document being inserted into the CREATE OR REPLACE VIEW univ_v OF XMLType WITH OBJECT ID (EXTRACT(OBJECT_VALUE, '/UNIVERSITY/@univNo').getNumberVal()) AS SELECT XMLELEMENT ("UNIVERSITY", XMLFOREST(univNo, univName), (SELECT XMLELEMENT("STUDENT", XMLAGG( XMLELEMENT("STUDENT", XMLFOREST(studNO as "Student", BA , Master) ) ) ) FROM Student s, University u WHERE s.univNo = u.univNo ) ) FROM University u; Listing 4. XMLType view definition.
There are two ways to keep data in a XMLType storage structure, in Oracle database system:  Store XML in CLOB XMLType.  Store XML as structured data, by the use of object-relational storage. In this situation, the shredded XML document is inserted into the underlying relational table, as a new row. In the view.php file only the second possibility was implemented (Building Database-Driven PHP Applications), as it is shown in listing 5.
It is worth emphasizing that XML data retrieved from the database with applied DOM fidelity consists of the same information as it was inserted into the database, with the exception of insignificant whitespaces.
In order to print out the result in a proper way (i.e. XML-formatted), the htmlspecialchars($strXMLData) function was called. Otherwise, only "pure" data -i.e. entries without tags, will be printed. The XML-formatted result of a sample query is shown in fig.  23, while "ordinary" one -in fig. 24 Besides, the possibility of formulating a simple XPath queries is provided in a described module. As it is presented in fig. 25, the queried XML document is assumed to be stored in a MOODLE platform server. In order to provide such functionality, a special PHP function that converts an XML file into an object should be utilized. By the use of: $doc =simplexml_load_file('XML_doc.xml'); assignment, all document elements are available. For example, in order to print BA-tagged data, $doc->student->BA argument should be used in the printf function. To facilitate the algorithm implementation, the document tree hierarchy is stored in a specially created table. Thus, the XPath query realization is reduced to the following steps:  Check the name of last-written tag.  Search the auxiliary table to get the level of the tag.  Convert the well-formed XML document in the given file to an object.  Loop through the elements at a specified level.  Print required data in a user's activity window.

Conclusion
In the chapter the possibility of using e-learning platform as an environment for education of XML language issues has been analyzed. Among them, basic XML structure elements and XML instance analysis were considered. For this purpose appropriate XML module and Synonym block, were created. The architecture of the module is similar to other built-in modules, but its functionality entailed introducing the specific solutions, suitable for tasks that XML module should implement. Additionally the simple mechanism, determining the number and difficulty of tasks to be solved by given learners, depending on their current progress, was proposed in the developed activity. It is based on numbers of their attempts undertaken to obtain proper task solution. Besides, more advanced XML language issues, directed to the group of participants being at a higher education level, were taken into consideration as well. Thus, retrieving relational data as XML and querying XML data with usage of advanced methods were implemented. All of the extensions were made using PHP scripts and were tested in the chosen database servers: MySQL, MS SQL Server and Oracle DBMS. Results of all tests were satisfactory, confirming preliminary assumptions for the possibility of using e-learning MOODLE platform as the environment for interactive teaching of XML language issues. However, there are some limitations in the proposed solution. One of them is the necessity to define the XML elements' attributes as the independent tags in XML instance and cannot be placed within other tags. Besides, there is no possibility to attach externally parsed entities to an XML document. Developed functionality does not cover the subject of XML Queries, either. Elimination of these limitations as well as evaluation of prepared solutions for wide group of beneficiaries are the first steps of the future work. Next, there is an addition planned to the presented work, extending grader report module with mechanisms assessing solutions of XML tasks. Furthermore, it is worth mentioning that the proposed functionality regards XML language issues but some of its mechanisms are generally enough to be exploited in other areas of education. The lexical analysis and text management (for instance in subject of programming languages) are good examples of such fields.