Parent

Methods

Class Index [+]

Quicksearch

TaskJuggler::XMLDocument

This class provides a rather simple XML document generator. It provides basic features to create a tree of XMLElements and to generate a XML String or file. It’s much less powerful than REXML but provides a more efficient API to create XMLDocuments with lots of attributes.

Public Class Methods

new(&block) click to toggle source

Create an empty XML document.

    # File lib/taskjuggler/XMLDocument.rb, line 25
25:     def initialize(&block)
26:       @elements = block ? yield(block) : []
27:     end

Public Instance Methods

<<(arg) click to toggle source

Add a top-level XMLElement.

    # File lib/taskjuggler/XMLDocument.rb, line 30
30:     def <<(arg)
31:       if arg.is_a?(Array)
32:         @elements += arg.flatten
33:       elsif arg.nil?
34:         # do nothing
35:       elsif arg.is_a?(XMLElement)
36:         @elements << arg
37:       else
38:         raise ArgumentError, "Unsupported argument of type #{arg.class}: " +
39:                              "#{arg.inspect}"
40:       end
41:     end
to_s() click to toggle source

Produce the XMLDocument as String.

    # File lib/taskjuggler/XMLDocument.rb, line 44
44:     def to_s
45:       str = ''
46:       @elements.each do |element|
47:         str << element.to_s(0)
48:       end
49: 
50:       str
51:     end
write(filename) click to toggle source

Write the XMLDocument to the specified file.

    # File lib/taskjuggler/XMLDocument.rb, line 54
54:     def write(filename)
55:       f = filename == '.' ? $stdout : File.new(filename.untaint, 'w')
56:       @elements.each do |element|
57:         f.puts element.to_s(0)
58:       end
59:       f.close unless f == $stdout
60:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.