2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
13 include('DiscussionTools.class.php');
16 * A class for DiscussionToolsParser
18 * http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_5/imsdt_v1p0_localised.xsd
20 class DiscussionToolsParser {
23 var $parser; // the XML handler
24 var $character_data; // tmp variable for storing the data
25 var $element_path; // array of element paths (basically a stack)
26 var $title; //link's title
27 var $text; //description
30 function DiscussionToolsParser(){
31 $this->parser = xml_parser_create();
33 xml_set_object($this->parser, $this);
34 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
35 xml_set_element_handler($this->parser, 'startElement', 'endElement');
36 xml_set_character_data_handler($this->parser, 'characterData');
40 // @return true if parsed successfully, false otherwise
41 function parse($xml_data) {
42 $this->element_path = array();
43 $this->character_data = '';
44 xml_parse($this->parser, $xml_data, TRUE);
48 function startElement($parser, $name, $attributes) {
52 $this->text_type = $attributes['texttype'];
55 array_push($this->element_path, $name);
59 /* called when an element ends */
60 /* removed the current element from the $path */
61 function endElement($parser, $name) {
64 $this->title = $this->character_data;
67 $this->text = $this->character_data;
71 //pop stack and reset character data, o/w it will stack up
72 array_pop($this->element_path);
73 $this->character_data = '';
77 function characterData($parser, $data){
80 $this->character_data .= preg_replace('/[\t\0\x0B(\r\n)]*/', '', $data);
81 // $this->character_data .= trim($data);
88 xml_parser_free($this->parser);
93 return new DiscussionTools($this->title, $this->text);