Class: ROXML::XML::Node

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(data) ⇒ Object



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

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



19
20
21
# File 'lib/roxml/xml/parsers/rexml.rb', line 19

def new_cdata(content)
  REXML::CData.new(content)
end

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



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

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

Instance Method Details

#==(other) ⇒ Object



42
43
44
# File 'lib/roxml/xml/parsers/rexml.rb', line 42

def ==(other)
  to_s == other.to_s
end

#add_child(child) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/roxml/xml/parsers/rexml.rb', line 34

def add_child(element)
  if element.is_a?(REXML::CData)
    REXML::CData.new(element, true, self)
  else
    add_element(element)
  end
end

#content=(string) ⇒ Object



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

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

#search(xpath) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/roxml/xml/parsers/rexml.rb', line 26

def search(xpath)
  begin
    REXML::XPath.match(self, xpath)
  rescue Exception => ex
    raise ex, xpath
  end
end

#set_libxml_contentObject



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

alias_method :set_libxml_content, :content=