Class: Moxml::Adapter::CustomizedLibxml::ProcessingInstruction

Inherits:
Node
  • Object
show all
Defined in:
lib/moxml/adapter/customized_libxml/processing_instruction.rb

Overview

Wrapper for LibXML processing instruction nodes

Instance Attribute Summary

Attributes inherited from Node

#native

Instance Method Summary collapse

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_xmlObject

Serialize as XML processing instruction LibXML auto-escapes content, we need to un-escape it



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/moxml/adapter/customized_libxml/processing_instruction.rb', line 12

def to_xml
  target = @native.name
  content = @native.content

  # Un-escape LibXML's automatic escaping
  if content && !content.empty?
    unescaped = content.gsub(""", '"')
      .gsub("'", "'")
      .gsub("&lt;", "<")
      .gsub("&gt;", ">")
      .gsub("&amp;", "&")
    "<?#{target} #{unescaped}?>"
  else
    "<?#{target}?>"
  end
end