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.
Add a top-level XMLElement.
# File lib/taskjuggler/XMLDocument.rb, line 28 def <<(arg) if arg.is_a?(Array) @elements += arg.flatten elsif arg.nil? # do nothing elsif arg.is_a?(XMLElement) @elements << arg else raise ArgumentError, "Unsupported argument of type #{arg.class}: " + "#{arg.inspect}" end end
Produce the XMLDocument as String.
# File lib/taskjuggler/XMLDocument.rb, line 42 def to_s str = '' @elements.each do |element| str << element.to_s(0) end str end
Write the XMLDocument to the specified file.
# File lib/taskjuggler/XMLDocument.rb, line 52 def write(filename) f = filename == '.' ? $stdout : File.new(filename.untaint, 'w') @elements.each do |element| f.puts element.to_s(0) end f.close unless f == $stdout end
Generated with the Darkfish Rdoc Generator 2.