[phpXML] Re: [phpXML] SKIP WHITE
Brought to you by:
bs_php,
nigelswinson
From: <fra...@vi...> - 2001-10-08 18:07:15
|
Ok, I find it out, hum had to read code, a couple of trim there and there I would like to make a greater function to support skipwhite and not skipwhite, but xml_parser_get_option can get this option value (I fill a bug report about it), good PHP! SO here my diff if you want to keep space in your cdata, note that if you patch your file you will get load_string too (look on passe post), make backup of your other one before doing it, this diff has been very low tested and it surely not supported by they maintainer!!!! Michael if you read this list, will you check to see if I don't broke anything. Thank you and cu. @@ -215,7 +215,7 @@ $parser = xml_parser_create(); // Set the options for parsing the XML data. - xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); + xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); // Set the object for the parser. @@ -246,6 +246,60 @@ $this->display_error("File %s could not be found or read.", $file); } } + + /** + * Reads a string and parses the XML data. + * + * This method reads the content of a XML string, tries to parse its + * content and upon success stores the information retrieved from + * the string into an array. + * + * @access public + * @author Francis Fillion <ffi...@in...> modified from Michael P. Mehl <mp...@ph...> + * @param string $content name of the string to be read and parsed. + * @see handle_start_element(), handle_end_element(), + * handle_character_data() + */ + function load_string ( $content ) + { + // Check whether content has been read. + if ( !empty($content) ) + { + // Create an XML parser. + $parser = xml_parser_create(); + + // Set the options for parsing the XML data. + xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); + xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); + + // Set the object for the parser. + xml_set_object($parser, &$this); + + // Set the element handlers for the parser. + xml_set_element_handler($parser, "handle_start_element", + "handle_end_element"); + xml_set_character_data_handler($parser, + "handle_character_data"); + + // Parse the XML file. + if ( !xml_parse($parser, $content, true) ) + { + // Display an error message. + $this->display_error("XML error in file %s, line %d: %s", + $content, xml_get_current_line_number($parser), + xml_error_string(xml_get_error_code($parser))); + } + + // Free the parser. + xml_parser_free($parser); + } + + else + { + // Display an error message. + $this->display_error("This xml document was empty", $content); + } + } /** * Generates a XML file with the content of the current document. @@ -324,7 +378,7 @@ } // Add the attribute to the XML data. - $xml .= " ".$key."=\"".trim(stripslashes($value))."\""; + $xml .= " ".$key."=\"".stripslashes($value)."\""; // Check whether this attribute is highlighted. if ( in_array($root."/attribute::".$key, $highlight) ) @@ -917,7 +971,8 @@ $text = strtr($text, $this->entities); // Save the text. - $this->add_content($this->path, addslashes(trim($text))); + //$this->add_content($this->path, addslashes(trim($text))); + $this->add_content($this->path, addslashes($text)); } /** @@ -1114,9 +1169,9 @@ $after = substr($step, $end + 1); // Trim each string. - $before = trim($before); - $between = trim($between); - $after = trim($after); + //$before = trim($before); + //$between = trim($between); + //$after = trim($after); // Save the evaluated function. $axis["axis"] = "function"; @@ -1627,9 +1682,9 @@ $after = substr($predicate, $end + 1); // Trim each string. - $before = trim($before); - $between = trim($between); - $after = trim($after); + //$before = trim($before); + //$between = trim($between); + // $after = trim($after); // Check whether there's something after the bracket. if ( !empty($after) ) @@ -3382,4 +3437,4 @@ } } -?> \ No newline at end of file +?> fra...@vi... wrote: > > DOes somebody know why does when I put a 0 instead of 1 in the > XML_OPTION_SKIP_WHITE in the xml_parser_set_option it still skip white? > IN the xml.php file? > > xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); > > An other thing why do we need /test[1] shouldn't it be /test? For > <test>untest</test> > > -- > Francis Fillion, BAA SI > Broadcasting live from his linux box. > And the maintainer of http://www.windplanet.com > > -- > This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ -- Francis Fillion, BAA SI Broadcasting live from his linux box. And the maintainer of http://www.windplanet.com -- This message has been sent through the <phpXML/> user discussion list. To unsubscribe, please visit https://sslsites.de/mailinglisten/user/us...@li.../ |