Jump to content

XML error: Invalid character !!!!


seco

Recommended Posts

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.

 

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));
            }
        }
    }
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.