Created
September 15, 2010 17:31
-
-
Save rickhull/581097 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0"?> | |
| <test>"'&<></test> | |
| Now monkey patching | |
| <?xml version="1.0"?> | |
| <test>"'&<></test> | |
| <!-- Notice there is no XML entity substitution for the single- and double-quotes --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rubygems' | |
| require 'nokogiri' | |
| # I want to have Nokogiri make the XML entity substitutions for all the characters "'&<> | |
| # | |
| puts Nokogiri::XML::Builder.new { |xml| xml.test %q("'&<>) }.to_xml | |
| puts "Now monkey patching" | |
| class Nokogiri::XML::Node | |
| alias old_encode_special_chars encode_special_chars | |
| def encode_special_chars(string) | |
| old_encode_special_chars(string).gsub("'", "'").gsub('"', """) | |
| end | |
| end | |
| puts Nokogiri::XML::Builder.new { |xml| xml.test %q("'&<>) }.to_xml | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment