Class: Moxml::Adapter::CustomizedLibxml::Cdata
- Defined in:
- lib/moxml/adapter/customized_libxml/cdata.rb
Overview
Wrapper for LibXML CDATA section nodes
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
-
#to_xml ⇒ Object
Serialize as XML CDATA section LibXML auto-escapes content, we need to un-escape it.
Methods inherited from Node
#==, #document, #document_present?, #hash, #initialize
Constructor Details
This class inherits a constructor from Moxml::Adapter::CustomizedLibxml::Node
Instance Method Details
#to_xml ⇒ Object
Serialize as XML CDATA section LibXML auto-escapes content, we need to un-escape it
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/moxml/adapter/customized_libxml/cdata.rb', line 12 def to_xml content = @native.content .gsub(""", '"') .gsub("'", "'") .gsub("<", "<") .gsub(">", ">") .gsub("&", "&") # Handle CDATA end marker escaping (]]> becomes ]]]]><![CDATA[>) # Replace all ]]> markers in the content before wrapping escaped_content = content.gsub("]]>", "]]]]><![CDATA[>") "<![CDATA[#{escaped_content}]]>" end |