-
-
Save TomyLobo/13b25cf663ab3bcaa96fd76c400e1ceb to your computer and use it in GitHub Desktop.
This file contains 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 'nokogiri' | |
require 'htmlentities' | |
# ... | |
class EntityReplacingVisitor | |
def visit(node) | |
if node.instance_of?(Nokogiri::XML::EntityReference) | |
@decoder ||= HTMLEntities.new | |
node.replace(@decoder.decode(node.to_xml)) | |
return | |
end | |
node.children.each do |child| | |
child.accept(self) | |
end | |
end | |
end | |
xml_doc = Nokogiri::XML(xml) do |configure| | |
configure.strict # strict parsing | |
end | |
xml_doc.accept(EntityReplacingVisitor.new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment