seco Posted January 5, 2008 Share Posted January 5, 2008 Hi this error appears to me when using xml_parser_create() why? the text im parsing is arabic and the xml file encoding is UTF8 any help ?? by the way no errors appear when the content of the xml is english text thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/84651-xml-error-invalid-character/ Share on other sites More sharing options...
effigy Posted January 5, 2008 Share Posted January 5, 2008 Does this help? Quote Link to comment https://forums.phpfreaks.com/topic/84651-xml-error-invalid-character/#findComment-431460 Share on other sites More sharing options...
seco Posted January 6, 2008 Author Share Posted January 6, 2008 thanks for reply i write xml_parser_set_option($this->xml,XML_OPTION_TARGET_ENCODING, "UTF-8"); xml_parser_set_option($this->xml,XML_OPTION_SKIP_WHITE,1); and still the same error message "XML error: Invalid character" i try also windows-1256 it says unsupported encoding any help? thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/84651-xml-error-invalid-character/#findComment-431729 Share on other sites More sharing options...
dsaba Posted January 6, 2008 Share Posted January 6, 2008 make sure the actual php script is encoded in utf-8 if your injecting the utf-8 variable from within the script post some problem code, duh? Quote Link to comment https://forums.phpfreaks.com/topic/84651-xml-error-invalid-character/#findComment-431733 Share on other sites More sharing options...
seco Posted January 6, 2008 Author Share Posted January 6, 2008 this is the class that return error when parsing xml <?php class XmlParser { var $xml; var $lastnode = array(); var $struct = array(); function XmlParser($xml) { $this->xml = xml_parser_create(''); //////////////////////////////////////////////////////////////////////////////////// xml_parser_set_option($this->xml,XML_OPTION_TARGET_ENCODING, "UTF-8"); xml_parser_set_option($this->xml,XML_OPTION_SKIP_WHITE,1); /////////////////////////////////////////////////////////////////////////////////// xml_set_object($this->xml, $this); xml_set_element_handler($this->xml, 'tag_open', 'tag_close'); xml_set_character_data_handler($this->xml, 'cdata'); $this->lastnode = array(&$this->struct); if (!xml_parse($this->xml, $xml)) { die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->xml)), xml_get_current_line_number($this->xml))); } xml_parser_free($this->xml); } function tag_open($parser, $tag, $attributes) { $c = count($this->lastnode) - 1; $this->lastnode[$c][] = array('tag' => $tag, 'attrib' => $attributes, 'data' => '', 'childs' => array()); $this->lastnode[] = &$this->lastnode[$c][count($this->lastnode[$c]) - 1]['childs']; } function tag_close($parser, $tag) { array_pop($this->lastnode); } function cdata($parser, $cdata) { if (strlen(ltrim($cdata)) > 0) { $p = count($this->lastnode) - 2; $this->lastnode[$p][count($this->lastnode[$p]) - 1]['data'] .= str_replace('\n', "\n", trim($cdata)); } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/84651-xml-error-invalid-character/#findComment-431745 Share on other sites More sharing options...
seco Posted January 6, 2008 Author Share Posted January 6, 2008 any idea why the parser fails with me Quote Link to comment https://forums.phpfreaks.com/topic/84651-xml-error-invalid-character/#findComment-431825 Share on other sites More sharing options...
seco Posted January 6, 2008 Author Share Posted January 6, 2008 thanks for reply i generate xml and using UTF-8 like $dom = new DOMDocument('1.0','UTF-8'); and generated successfully and then this xml file is parsed with the upper class xmlparser it gives me xml error because the non-english content any help please? thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/84651-xml-error-invalid-character/#findComment-431879 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.