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 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
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 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.
Generated with the Darkfish Rdoc Generator 1.1.6.