2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2009 */
6 /* Inclusive Design Institute */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
14 include('DiscussionTools.class.php');
17 * A class for DiscussionToolsParser
19 * http://www.imsglobal.org/profile/cc/ccv1p0/derived_schema/domainProfile_5/imsdt_v1p0_localised.xsd
21 class DiscussionToolsParser {
24 var $parser; // the XML handler
25 var $character_data; // tmp variable for storing the data
26 var $element_path; // array of element paths (basically a stack)
27 var $title; //link's title
28 var $text; //description
31 function DiscussionToolsParser(){
32 $this->parser = xml_parser_create();
34 xml_set_object($this->parser, $this);
35 xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false); /* conform to W3C specs */
36 xml_set_element_handler($this->parser, 'startElement', 'endElement');
37 xml_set_character_data_handler($this->parser, 'characterData');
41 // @return true if parsed successfully, false otherwise
42 function parse($xml_data) {
43 $this->element_path = array();
44 $this->character_data = '';
45 xml_parse($this->parser, $xml_data, TRUE);
49 function startElement($parser, $name, $attributes) {
53 $this->text_type = $attributes['texttype'];
56 array_push($this->element_path, $name);
60 /* called when an element ends */
61 /* removed the current element from the $path */
62 function endElement($parser, $name) {
65 $this->title = $this->character_data;
68 $this->text = $this->character_data;
72 //pop stack and reset character data, o/w it will stack up
73 array_pop($this->element_path);
74 $this->character_data = '';
78 function characterData($parser, $data){
81 $this->character_data .= preg_replace('/[\t\0\x0B(\r\n)]*/', '', $data);
82 // $this->character_data .= trim($data);
89 xml_parser_free($this->parser);
94 return new DiscussionTools($this->title, $this->text);