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 .
[...] posted a temporary fix for Wordpress that takes the raw xml and replaces the offending entities with characters. He found three places. [...]
[...] via WordPress patch for problamatic libxml2 version « HooFoo Blog. [...]
Thanks, I have made the changes and it works well. Is there any reason why it would mess up some of the plugin options? I noticed that WordTube settings were corrupted after installing the updated files, but i’m not sure if this was related?
All of the option boxes within WordTube contained “a”… after resetting to the defaults, it seems to work fine.
I am not fan of wordTube , any how I download and just go through the code, The WordTube also using “xml_parse_into_struct” function , this may be the cause.
Location -
wordtube/admin/function.php line no = 342
try to apply this patch to this location, and share with others
regards
[...] http://blog.hoofoo.net/2009/01/14/wordpress-patch-for-problamatic-libxml2-version/ [...]
[...] WordPress patch for problamatic libxml2 version [...]
[...] well together: the blame seems to be on libxml2, but regardless the dude over at HooFoo wrote up a quick fix. Two [...]
Thanks, still having the same prob aftr patching i think i need the workaround applied on the other files aswell, would be great if you could provide them as well. would be great if you could mail me in the all the patched files or share a link from where i or others could download.
please do a better job explaining where each file is located
thanks
[...] Update: Users have reported mixed results with the attached fix. It works for some and doesn’t for others. If it’s not working for you check if the files have been uploaded in the right place. Alternatively, try making the changes manually as listed in the tutorial by Hoofoo. [...]
Hi all
New Libxml 2.7.3 also not working , LIBXML_DOTTED_VERSION == ‘2.7.3′
Now code changes look like this.
//xmllib 2.7.0 -2.7.3 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′ ||
LIBXML_DOTTED_VERSION == ‘2.7.3′
){
#Replase code like above
}
$status = xml_parse( $this->parser, $source );
Hi All
To Find Code Location just try search “xml_parse” Method usages.
I have used Netbean IDE For my php development.
Get Free Netbean PHP IDE and edit your wordpress code.
any how I will put the php file locations
blogger.php, wp-admin/import
blogger_mearge.php, wp-admin/import
link-parse-opml.php, wp-admin
atomlib.php, wp-includes
class-IXR.php, wp-includes
feed.php, wp-includes
rss.php, wp-includes
regards
This fix worked great, updated the three files as stated. I am using wordpress 2.5 (not sure if that was the issue) but I got an error on the rss.php, to fix it I removed the if condition containing LIBXML_DOTTED_VERSION.
//xmllib 2.7.0 -2.7.2 stripping leading angle brackets bug patch
$source =str_replace(”<”,”<”,$source );
$source =str_replace(”>”,”>”,$source );
$source =str_replace(”&”,”&”,$source );
//end fix
I tested, it doesn’t work. Not at least for posting to my blog.
Any update with this? I can’t get it to work in my blog!!! And tired of waiting for php6… I have Libxml 2.7.3 the this code doesn´t work!
//xmllib 2.7.0 -2.7.3 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? ||
LIBXML_DOTTED_VERSION == ‘2.7.3?
){
I can’t live without LW! :S
YES!!!! YOU ARE THE BEST!!! Thank you all so much!
Solved the problem! (my error!!! :))
[...] one hardworking fellow figured out how to modify a few WordPress files to get things working again. If you’re not comfy with editing the code yourself, another [...]
Hi Felix Ker
Check you code again , most people get encoded code from site , Please check exact code.
regard.
thank you my friend, you’re the man.
now i can patch my WP blog using your code
again, thanks so much…
I made an archive with modified files, form this patch. It’s work.
Who don’t like modify source code, can download my archive from that page: http://multica.net.ru/2009/02/24/reshili-problemku/
PS: sorry for my english…
it’s good trick,
thank a lot , now , I can posting wordpress using XMLRPC.very well.
" is stripped too!
Please add following line:
$xml = str_ireplace(’"’, ‘"’, $xml);
I’ll contact my webhost to update the library but this plugin works:
http://wordpress.org/extend/plugins/libxml2-fix/
(the manual fix to comment out didn’t work out for me, as well as just unpacking the .zip)
yes , this work only for xmlrpc methods. but there are many locations using libxml .
angryden is correct that quotes are also stripped. You will want to use the HTML name for double quotes ‘ & quot; ‘ and ascii code ‘ & #34 ‘ , minus the space after the ampersand. I am willing to bet any character with an HTML name equivalent is stripped, basically all of the above mentioned plus any character with an ASCII code >= 160. This includes non-breaking space ( & nbsp; )