Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.