Class: ROXML::XML::Node

Inherits:
Object
  • Object
show all
Includes:
NamespacedSearch, NodeExtensions
Defined in:
lib/roxml/xml.rb,
lib/roxml/xml/parsers/libxml.rb,
lib/roxml/xml/parsers/nokogiri.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NodeExtensions

#attributes, #search

Methods included from NamespacedSearch

#search

Class Method Details

.from(data) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/roxml/xml.rb', line 22

def self.from(data)
  case data
  when XML::Node
    data
  when XML::Document
    data.root
  when File, IO
    Parser.parse_io(data).root
  else
    if (defined?(URI) && data.is_a?(URI::Generic)) ||
       (defined?(Pathname) && data.is_a?(Pathname))
      Parser.parse_file(data.to_s).root
    else
      Parser.parse(data).root
    end
  end
end

.new_cdata(content) ⇒ Object



65
66
67
# File 'lib/roxml/xml/parsers/nokogiri.rb', line 65

def new_cdata(content)
  Nokogiri::XML::CDATA.new(Document.new, content)
end

.new_with_entity_escaping(name, content = nil, namespace = nil) ⇒ Object



51
52
53
# File 'lib/roxml/xml/parsers/libxml.rb', line 51

def new_with_entity_escaping(name, content = nil, namespace = nil)
  new_without_entity_escaping(name, content && CGI.escapeHTML(content), namespace)
end

Instance Method Details

#add_child(child) ⇒ Object



63
64
65
66
67
# File 'lib/roxml/xml/parsers/libxml.rb', line 63

def add_child(child)
  # libxml 1.1.3 changed child_add from returning child to returning self
  self << child
  child
end

#content=(string) ⇒ Object



70
71
72
# File 'lib/roxml/xml/parsers/libxml.rb', line 70

def content=(string)
  set_libxml_content(string.gsub('&', '&amp;'))
end

#default_namespaceObject



59
60
61
# File 'lib/roxml/xml/parsers/libxml.rb', line 59

def default_namespace
  doc.default_namespace
end

#set_libxml_contentObject



69
# File 'lib/roxml/xml/parsers/libxml.rb', line 69

alias_method :set_libxml_content, :content=