[Phpxd-commits] CVS: phpXD/include/parser DOMParser.php,1.1,1.2
Status: Beta
Brought to you by:
growbal
From: Thomas D. <th...@us...> - 2002-01-25 22:29:29
|
Update of /cvsroot/phpxd/phpXD/include/parser In directory usw-pr-cvs1:/tmp/cvs-serv15665/include/parser Modified Files: DOMParser.php Log Message: Added function to parse strings. Index: DOMParser.php =================================================================== RCS file: /cvsroot/phpxd/phpXD/include/parser/DOMParser.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** DOMParser.php 2002/01/25 22:18:18 1.1 --- DOMParser.php 2002/01/25 22:29:26 1.2 *************** *** 126,129 **** --- 126,167 ---- } } + + /** + * Loads XML string specified by $str and creates the DOM tree. + * + * @public + * @param $str <code>string</code> + * @returns phpXD + */ + function parse($str) { + if (!empty($str)) { + $this->document = new Document(); + + $parser = xml_parser_create(); + + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); + + xml_set_object($parser, $this); + + xml_set_element_handler($parser, "handleStartElement", + "handleEndElement"); + xml_set_character_data_handler($parser, "handleCharacterData"); + xml_set_processing_instruction_handler($parser, + "handleProcessingInstruction"); + xml_set_default_handler($parser, "handleDefault"); + + if (!xml_parse($parser, $str, true)) { + $this->displayError("XML error in XML-String, line %d: %s", + xml_get_current_line_number($parser), + xml_error_string(xml_get_error_code($parser))); + } + + xml_parser_free($parser); + return $this->document; + } + else { + $this->displayError("The string is empty."); + } + } /** |