Module: ROXML::XML

Defined in:
lib/roxml/xml/parsers/libxml.rb,
lib/roxml/xml.rb,
lib/roxml/xml/parsers/nokogiri.rb

Overview

:nodoc:all

Class Method Summary collapse

Class Method Details

.add_cdata(parent, content) ⇒ Object



23
24
25
# File 'lib/roxml/xml/parsers/libxml.rb', line 23

def add_cdata(parent, content)
  parent.add_child(Nokogiri::XML::CDATA.new(parent.document, content))
end

.add_child(parent, child) ⇒ Object



27
28
29
# File 'lib/roxml/xml/parsers/libxml.rb', line 27

def add_child(parent, child)
  parent.add_child(child)
end

.add_node(parent, name) ⇒ Object



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

def add_node(parent, name)
  add_child(parent, Nokogiri::XML::Node.new(name, parent.document))
end

.new_node(name) ⇒ Object



15
16
17
# File 'lib/roxml/xml/parsers/libxml.rb', line 15

def new_node(name)
  Nokogiri::XML::Node.new(name, Document.new)
end

.parse_file(path) ⇒ Object



36
37
38
39
# File 'lib/roxml/xml/parsers/libxml.rb', line 36

def parse_file(path)
  path = path.sub('file:', '') if path.starts_with?('file:')
  parse_io(open(path))
end

.parse_io(stream) ⇒ Object



40
41
42
# File 'lib/roxml/xml/parsers/libxml.rb', line 40

def parse_io(stream)
  Nokogiri::XML(stream)
end

.parse_string(string) ⇒ Object



32
33
34
# File 'lib/roxml/xml/parsers/libxml.rb', line 32

def parse_string(string)
  Nokogiri::XML(string)
end

.save_doc(doc, path) ⇒ Object



44
45
46
47
48
# File 'lib/roxml/xml/parsers/libxml.rb', line 44

def save_doc(doc, path)
  open(path, 'w') do |file|
    file << doc.serialize
  end
end

.set_attribute(node, name, value) ⇒ Object



7
8
9
# File 'lib/roxml/xml/parsers/libxml.rb', line 7

def set_attribute(node, name, value)
  node[name] = value
end

.set_content(node, content) ⇒ Object



11
12
13
# File 'lib/roxml/xml/parsers/libxml.rb', line 11

def set_content(node, content)
  node.content = content
end