-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME
40 lines (26 loc) · 1021 Bytes
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
XML Node
==========
Example for generating xml:
# Create an atom like document
root = XmlNode.new 'feed' do |feed|
feed << XmlNode.new('id', 'tag:atom.com,2007:1')
feed << XmlNode.new('title', 'Atom test feed')
feed << XmlNode.new('author') do |author|
author << XmlNode.new("name", "tobi")
author << XmlNode.new("email", "[email protected]")
end
feed << XmlNode.new('entry') do |entry|
entry << XmlNode.new('title', 'First post')
entry << XmlNode.new('summary', 'Lorem ipsum', :type => 'xhtml')
entry << XmlNode.new('created_at', Time.now)
end
feed << XmlNode.new('dc:published', Time.now)
end
root.to_xml #=> Well formatted xml
Example for parsing xml:
xml = XmlNode.parse('<feed attr="1"><element>text</element><element>text</element></feed>')
xml['attr'] #=> '1'
xml.find(:first, 'element')
xml.find(:all, 'element')
xml.children['element'].text #=> 'text'
xml.children.each { |e| e... }