I have gone throught many post regarding wordpress problem with buggy libxml2 version, The many woraround was downgrade libxml2 version to 2.6.32 or older. The current version of libxml2 2.7.2 also have bug ’stripping leading angle brackets and & sign’.
Many wordpress use shared hosting plan and can not downgrade libxml2. This is for you , I like to shara with you.
Known wordpress problems with libxml2
XMLRPC api stripping leading angle brackets (when you post using blog writer , Flickr or any xmlrpc API your post <>& are missing).
Blogger Importer mising URL etc.
Remove ‘<>&’ character from RSS widget result urls.
Any not specified here please comment.
Wordpress libxml2 USE files
blogger.php, blogger_mearge.php, link-parse-opml.php, atomlib.php, class-IXR.php, feed.php, rss.php
Workaround patch for wordpress
Currently I have modified 3 files those are blogger.php, class-IXR.php and rss.php. If you found any isue in oter files please reply this post.
Before going to call xml_parse fuction put this code segment
//xmllib 2.7.0 -2.7.2 stripping leading angle brackets bug patch
if(LIBXML_DOTTED_VERSION == ‘2.7.0′ ||
LIBXML_DOTTED_VERSION == ‘2.7.1′ ||
LIBXML_DOTTED_VERSION == ‘2.7.2′
){
$xml =str_replace(”<”,”<”,$xml );
$xml =str_replace(”>”,”>”,$xml );
$xml =str_replace(”&”,”&”,$xml );
}
//end Fix
xml_parse($parser, $xml);
blogger.php Patch update parse function
function parse($xml) {
global $app_logging;
array_unshift($this->ns_contexts, array());
$parser = xml_parser_create_ns();
xml_set_object($parser, $this);
xml_set_element_handler($parser, “start_element”, “end_element”);
xml_parser_set_option($parser,XML_OPTION_CASE_FOLDING,0);
xml_parser_set_option($parser,XML_OPTION_SKIP_WHITE,0);
xml_set_character_data_handler($parser, “cdata”);
xml_set_default_handler($parser, “_default”);
xml_set_start_namespace_decl_handler($parser, “start_ns”);
xml_set_end_namespace_decl_handler($parser, “end_ns”);
$contents = “”;
//xmllib 2.7.0 -2.7.2 stripping leading angle brackets bug patch
if(LIBXML_DOTTED_VERSION == ‘2.7.0′ ||
LIBXML_DOTTED_VERSION == ‘2.7.1′ ||
LIBXML_DOTTED_VERSION == ‘2.7.2′
){
$xml =str_replace(”<”,”<”,$xml );
$xml =str_replace(”>”,”>”,$xml );
$xml =str_replace(”&”,”&”,$xml );
}
//end Fix
xml_parse($parser, $xml);
xml_parser_free($parser);
return true;
}
class-IXR.php Patch update parse function
function parse() {
// first remove the XML declaration
$this->message = preg_replace(’/<\?xml(.*)?\?’.'>/’, ”, $this->message);
if (trim($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’);
//xmllib 2.7.0 -2.7.2 stripping leading angle brackets bug patch
if(LIBXML_DOTTED_VERSION == ‘2.7.0′ ||
LIBXML_DOTTED_VERSION == ‘2.7.1′ ||
LIBXML_DOTTED_VERSION == ‘2.7.2′
){
$this->message =str_replace(”<”,”<”,$this->message);
$this->message =str_replace(”>”,”>”,$this->message);
$this->message =str_replace(”&”,”&”,$this->message);
}
if (!xml_parse($this->_parser, $this->message)) {
/* die(sprintf(’XML error: %s at line %d’,
xml_error_string(xml_get_error_code($this->_parser)),
xml_get_current_line_number($this->_parser))); */
return false;
}
xml_parser_free($this->_parser);
// Grab the error messages, if any
if ($this->messageType == ‘fault’) {
$this->faultCode = $this->params[0]['faultCode'];
$this->faultString = $this->params[0]['faultString'];
}
return true;
}
rss.php Patch update MagpieRSS function
function MagpieRSS ($source) {
# if PHP xml isn’t compiled in, die
#
if ( !function_exists(’xml_parser_create’) )
trigger_error( “Failed to load PHP’s XML Extension. http://www.php.net/manual/en/ref.xml.php” );
$parser = @xml_parser_create();
if ( !is_resource($parser) )
trigger_error( “Failed to create an instance of PHP’s XML parser. http://www.php.net/manual/en/ref.xml.php”);
$this->parser = $parser;
# pass in parser, and a reference to this object
# setup 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’ );
//xmllib 2.7.0 -2.7.2 stripping leading angle brackets bug patch
if(LIBXML_DOTTED_VERSION == ‘2.7.0′ ||
LIBXML_DOTTED_VERSION == ‘2.7.1′ ||
LIBXML_DOTTED_VERSION == ‘2.7.2′
){
$source =str_replace(”<”,”<”,$source );
$source =str_replace(”>”,”>”,$source );
$source =str_replace(”&”,”&”,$source );
}
$status = xml_parse( $this->parser, $source );
if (! $status ) {
$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 );
$this->normalize();
}
Note
I have check only for 3 libxml version , If you need this patch for other version please reply or modify your self.
Updates
New libxml ‘2.7.3′ also not working , add this version also above code .