xml_parser_create example


                $this->error_string = 'SimplePie bug! Please report this!';
                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);
            
throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
        }

        if (empty($options['useId'])) {
            $this->_useId = false;
        } else {
            $this->_useId = true;
        }

        $encoding      = $this->_findEncoding($filename);
        $this->_target = $locale;
        $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);
            
/** * PHP5 constructor. */
    function __construct( $source ) {

        # Check if PHP xml isn't compiled         #         if ( ! function_exists('xml_parser_create') ) {
            return trigger_error( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." );
        }

        $parser = xml_parser_create();

        $this->parser = $parser;

        # pass in parser, and a reference to this object         # set up handlers         #         xml_set_object( $this->parser, $this );
        xml_set_element_handler($this->parser,
                'feed_start_element', 'feed_end_element' );

        xml_set_character_data_handler( $this->parser, 'feed_cdata' );

        

function endElement( $parser$tag_name ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid     // Nothing to do. }

// Create an XML parser. 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." ) );
    wp_die( __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
}

$xml_parser = xml_parser_create();

// Set the functions to handle opening and closing tags. xml_set_element_handler( $xml_parser, 'startElement', 'endElement' );

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

            $element_limit = apply_filters( 'xmlrpc_element_limit', $element_limit );
        }
        if ( $element_limit && 2 * $element_limit < substr_count( $this->message, '<' ) ) {
            return false;
        }

        $this->_parser = xml_parser_create();
        // Set XML parser to take the case of tags in to account         xml_parser_set_option($this->_parser, XML_OPTION_CASE_FOLDING, false);
        // Set XML parser callback functions         xml_set_object($this->_parser, $this);
        xml_set_element_handler($this->_parser, 'tag_open', 'tag_close');
        xml_set_character_data_handler($this->_parser, 'cdata');

        // 256Kb, parse in chunks to avoid the RAM usage on very large messages         $chunk_size = 262144;

        /** * Filters the chunk size that can be used to parse an XML-RPC response message. * * @since 4.4.0 * * @param int $chunk_size Chunk size to parse in bytes. */

        $this->_data = array();
        if (!is_readable($filename)) {
            throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
        }

        if (isset($options['useId'])) {
            $this->_useId = (boolean) $options['useId'];
        }

        $encoding = $this->_findEncoding($filename);
        $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);
            
function prep_atom_text_construct( $data ) {
    if ( ! str_contains( $data, '<' ) && ! str_contains( $data, '&' ) ) {
        return array( 'text', $data );
    }

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

    protected function _loadTranslationData($filename$locale, array $options = array())
    {
        $this->_data = array();
        if (!is_readable($filename)) {
            throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
        }

        $encoding = $this->_findEncoding($filename);
        $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);
            

    protected function _loadTranslationData($filename$locale, array $options = array())
    {
        $this->_data = array();
        if (!is_readable($filename)) {
            throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
        }

        $this->_target = $locale;

        $encoding = $this->_findEncoding($filename);
        $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);
            

    protected function _loadTranslationData($filename$locale, array $options = array())
    {
        $this->_data = array();
        $this->_lang = $locale;
        if (!is_readable($filename)) {
            throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
        }

        $encoding    = $this->_findEncoding($filename);
        $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);
            
        if (!extension_loaded('xml') || !extension_loaded('pcre'))
        {
            $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
Home | Imprint | This part of the site doesn't use cookies.