xml_parser_free example

if(!xml_parse($parser$datafeof($fp))) {
                /* translators: 1: Error message, 2: Line number. */
                trigger_error(sprintf(__('XML Error: %1$s at line %2$s')."\n",
                    xml_error_string(xml_get_error_code($parser)),
                    xml_get_current_line_number($parser)));
                $ret = false;
                break;
            }
        }
        fclose($fp);

        xml_parser_free($parser);
        unset($parser);

        restore_error_handler();

        return $ret;
    }

    function start_element($parser$name$attrs) {

        $name_parts = explode(":", $name);
        $tag        = array_pop($name_parts);

        
$this->error = 'XML or PCRE extensions not loaded!';
            return false;
        }
        // Then check the xml extension is sane (i.e., libxml 2.7.x issue on PHP < 5.2.9 and libxml 2.7.0 to 2.7.2 on any version) if we don't have xmlreader.         elseif (!extension_loaded('xmlreader'))
        {
            static $xml_is_sane = null;
            if ($xml_is_sane === null)
            {
                $parser_check = xml_parser_create();
                xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
                xml_parser_free($parser_check);
                $xml_is_sane = isset($values[0]['value']);
            }
            if (!$xml_is_sane)
            {
                return false;
            }
        }

        // The default sanitize class gets set in the constructor, check if it has         // changed.         if ($this->registry->get_class('Sanitize') !== 'SimplePie_Sanitize') {
            
$errorcode = xml_get_error_code( $this->parser );
            if ( $errorcode != XML_ERROR_NONE ) {
                $xml_error = xml_error_string( $errorcode );
                $error_line = xml_get_current_line_number($this->parser);
                $error_col = xml_get_current_column_number($this->parser);
                $errormsg = "$xml_error at line $error_line, column $error_col";

                $this->error( $errormsg );
            }
        }

        xml_parser_free( $this->parser );
        unset( $this->parser );

        $this->normalize();
    }

    /** * PHP4 constructor. */
    public function MagpieRSS( $source ) {
        self::__construct( $source );
    }

    
$this->_file = xml_parser_create($encoding);
        xml_set_object($this->_file, $this);
        xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
        xml_set_element_handler($this->_file, "_startElement", "_endElement");
        xml_set_character_data_handler($this->_file, "_contentElement");

        if (!xml_parse($this->_file, file_get_contents($filename))) {
            $ex = sprintf('XML error: %s at line %d of file %s',
                          xml_error_string(xml_get_error_code($this->_file)),
                          xml_get_current_line_number($this->_file),
                          $filename);
            xml_parser_free($this->_file);
            throw new Zend_Translate_Exception($ex);
        }

        return $this->_data;
    }

    /** * Internal method, called by xml element handler at start * * @param resource $file File handler * @param string $name Elements name * @param array $attrib Attributes for this element */


    if ( ! function_exists( 'xml_parser_create' ) ) {
        trigger_error( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );

        return array( 'html', "<![CDATA[$data]]>" );
    }

    $parser = xml_parser_create();
    xml_parse( $parser, '<div>' . $data . '</div>', true );
    $code = xml_get_error_code( $parser );
    xml_parser_free( $parser );
    unset( $parser );

    if ( ! $code ) {
        if ( ! str_contains( $data, '<' ) ) {
            return array( 'text', $data );
        } else {
            $data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
            return array( 'xhtml', $data );
        }
    }

    
$this->_file   = xml_parser_create($encoding);
        xml_set_object($this->_file, $this);
        xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
        xml_set_element_handler($this->_file, "_startElement", "_endElement");
        xml_set_character_data_handler($this->_file, "_contentElement");

        if (!xml_parse($this->_file, file_get_contents($filename))) {
            $ex = sprintf('XML error: %s at line %d of file %s',
                          xml_error_string(xml_get_error_code($this->_file)),
                          xml_get_current_line_number($this->_file),
                          $filename);
            xml_parser_free($this->_file);
            throw new Zend_Translate_Exception($ex);
        }

        return $this->_data;
    }

    private function _startElement($file$name$attrib)
    {
        if ($this->_stag === true) {
            $this->_scontent .= "<".$name;
            foreach($attrib as $key => $value) {
                
$this->_file = xml_parser_create($encoding);
        xml_set_object($this->_file, $this);
        xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
        xml_set_element_handler($this->_file, "_startElement", "_endElement");
        xml_set_character_data_handler($this->_file, "_contentElement");

        if (!xml_parse($this->_file, file_get_contents($filename))) {
            $ex = sprintf('XML error: %s at line %d of file %s',
                          xml_error_string(xml_get_error_code($this->_file)),
                          xml_get_current_line_number($this->_file),
                          $filename);
            xml_parser_free($this->_file);
            throw new Zend_Translate_Exception($ex);
        }

        return $this->_data;
    }

    private function _startElement($file$name$attrib)
    {
        switch(strtolower($name)) {
            case 'message':
                $this->_source = null;
                
return false;
            }
        }

        $return = true;

        static $xml_is_sane = null;
        if ($xml_is_sane === null)
        {
            $parser_check = xml_parser_create();
            xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
            xml_parser_free($parser_check);
            $xml_is_sane = isset($values[0]['value']);
        }

        // Create the parser         if ($xml_is_sane)
        {
            $xml = xml_parser_create_ns($this->encoding, $this->separator);
            xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
            xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
            xml_set_object($xml$this);
            xml_set_character_data_handler($xml, 'cdata');
            
$final = false;

        do {
            if (strlen($this->message) <= $chunk_size) {
                $final = true;
            }

            $part = substr($this->message, 0, $chunk_size);
            $this->message = substr($this->message, $chunk_size);

            if (!xml_parse($this->_parser, $part$final)) {
                xml_parser_free($this->_parser);
                unset($this->_parser);
                return false;
            }

            if ($final) {
                break;
            }
        } while (true);

        xml_parser_free($this->_parser);
        unset($this->_parser);

        
$this->_file = xml_parser_create($encoding);
        xml_set_object($this->_file, $this);
        xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
        xml_set_element_handler($this->_file, "_startElement", "_endElement");
        xml_set_character_data_handler($this->_file, "_contentElement");

        if (!xml_parse($this->_file, file_get_contents($filename))) {
            $ex = sprintf('XML error: %s at line %d of file %s',
                          xml_error_string(xml_get_error_code($this->_file)),
                          xml_get_current_line_number($this->_file),
                          $filename);
            xml_parser_free($this->_file);
            throw new Zend_Translate_Exception($ex);
        }

        return $this->_data;
    }

    private function _startElement($file$name$attrib)
    {
        switch(strtolower($name)) {
            case 'tm:tu':
                $this->_tag     = $attrib['id'];
                
if ( ! xml_parse( $xml_parser$opml, true ) ) {
    printf(
        /* translators: 1: Error message, 2: Line number. */
        __( 'XML Error: %1$s at line %2$s' ),
        xml_error_string( xml_get_error_code( $xml_parser ) ),
        xml_get_current_line_number( $xml_parser )
    );
}

// Free up memory used by the XML parser. xml_parser_free( $xml_parser );
unset( $xml_parser );
$this->_file = xml_parser_create($encoding);
        xml_set_object($this->_file, $this);
        xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
        xml_set_element_handler($this->_file, "_startElement", "_endElement");
        xml_set_character_data_handler($this->_file, "_contentElement");

        if (!xml_parse($this->_file, file_get_contents($filename))) {
            $ex = sprintf('XML error: %s at line %d of file %s',
                          xml_error_string(xml_get_error_code($this->_file)),
                          xml_get_current_line_number($this->_file),
                          $filename);
            xml_parser_free($this->_file);
            throw new Zend_Translate_Exception($ex);
        }

        return $this->_data;
    }

    private function _startElement($file$name$attrib)
    {
        if ($this->_term !== null) {
            $this->_content .= "<".$name;
            foreach($attrib as $key => $value) {
                
Home | Imprint | This part of the site doesn't use cookies.