Class: KXML::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/xml/kxml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) {|@root| ... } ⇒ Document

Returns a new instance of Document.

Yields:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/xml/kxml.rb', line 7

def initialize(data)
	case data
	when KXML::Node
		@root = data
	when String
		if data =~ /^[<>\/]/
			parse_from_string(data)
		else
			@root = Node.new(data)
		end
	when File
		parse_from_file(data)
	else
		raise "Unsupport Param Type : #{data.class}"
	end
	yield @root if block_given?
end

Instance Attribute Details

#encodingObject

Returns the value of attribute encoding.



3
4
5
# File 'lib/xml/kxml.rb', line 3

def encoding
  @encoding
end

#rootObject

Returns the value of attribute root.



5
6
7
# File 'lib/xml/kxml.rb', line 5

def root
  @root
end

#versionObject

Returns the value of attribute version.



4
5
6
# File 'lib/xml/kxml.rb', line 4

def version
  @version
end

Instance Method Details

#save_to(file_path) ⇒ Object



25
26
27
28
29
# File 'lib/xml/kxml.rb', line 25

def save_to(file_path)
	File.open(file_path,"w+"){|f|
		f.write to_s
	}
end

#to_s(format = Format::PRETTY) ⇒ Object



31
32
33
# File 'lib/xml/kxml.rb', line 31

def to_s(format = Format::PRETTY)
	return @root.to_s(format)
end