Class: Moxml::Adapter::CustomizedLibxml::Text
- Defined in:
- lib/moxml/adapter/customized_libxml/text.rb
Overview
Wrapper for LibXML text nodes
Instance Attribute Summary
Attributes inherited from Node
Instance Method Summary collapse
- #text ⇒ Object
- #to_s ⇒ Object
-
#to_xml ⇒ Object
Serialize as XML with proper escaping LibXML’s .content already contains escaped text, but it over-escapes quotes which don’t need escaping in text nodes (only in attributes).
Methods inherited from Node
#==, #document, #document_present?, #hash, #initialize
Constructor Details
This class inherits a constructor from Moxml::Adapter::CustomizedLibxml::Node
Instance Method Details
#text ⇒ Object
12 13 14 |
# File 'lib/moxml/adapter/customized_libxml/text.rb', line 12 def text @native.content end |
#to_s ⇒ Object
8 9 10 |
# File 'lib/moxml/adapter/customized_libxml/text.rb', line 8 def to_s @native.content end |
#to_xml ⇒ Object
Serialize as XML with proper escaping LibXML’s .content already contains escaped text, but it over-escapes quotes which don’t need escaping in text nodes (only in attributes)
19 20 21 22 23 24 25 26 |
# File 'lib/moxml/adapter/customized_libxml/text.rb', line 19 def to_xml content = @native.content # Skip the gsub allocation entirely when there's nothing to undo — # the common case for parsed text without literal quotes. return content unless content.include?(""") content.gsub(""", '"') end |