Tweak IE Conditional Comment with Nokogiri without converting entities

JUF

New Member
I have an XHTML file with an HTML5 Shiv in the head:\[code\]<!--[if lt IE 9]> <script src='http://stackoverflow.com/questions/common/html5.js' type='text/javascript'></script><![endif]-->\[/code\]Using Nokogiri I need to adjust the path in that comment, stripping off the \[code\]../\[/code\]. However, any changes to the \[code\].content\[/code\] of the comment node results in XML output that converts the \[code\]>\[/code\] and \[code\]<\[/code\] to entities:\[code\]XML = <<ENDXML<r><!--[if lt IE 9]> <script src='http://stackoverflow.com/questions/common/html5.js' type='text/javascript'></script><![endif]--></r>ENDXMLrequire 'nokogiri'doc = Nokogiri.XML(XML)comment = doc.at_xpath('//comment()')comment.content = comment.content.sub('../','')puts comment.to_xml#=> <!--[if lt IE 9]>#=> <script src='http://stackoverflow.com/questions/11315362/common/html5.js' type='text/javascript'></script>#=> <![endif]-->\[/code\]The original source is valid XML/XHTML. How can I get Nokogiri not to convert the entities inside this comment during tweaking?
 
Back
Top