28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/douban/event.rb', line 28
def initialize(atom='')
doc = case atom
when REXML::Document then atom.root
when REXML::Element then atom
else REXML::Document.new(atom).root
end
@id=REXML::XPath.first(doc,"./id/text()").to_s
title=REXML::XPath.first(doc,"./title")
@title=title.text if title
@category={}
category=REXML::XPath.first(doc,"./category")
@category['term']=category.attributes['term'] if category
@category['scheme']=category.attributes['scheme'] if category
@author||=Author.new
name=REXML::XPath.first(doc,"//author/name")
@author.name=name.text if name
uri=REXML::XPath.first(doc,"//author/uri")
@author.uri=uri.text if uri
REXML::XPath.each(doc,"//author/link") do |link|
@author.link||={}
@author.link[link.attributes['rel']]=link.attributes['href']
end
summary=REXML::XPath.first(doc,"./summary")
@summary=summary.text if summary
content=REXML::XPath.first(doc,"./content")
@content=content.text if content
REXML::XPath.each(doc,"./link") do |link|
@link||={}
@link[link.attributes['rel']]=link.attributes['href']
end
REXML::XPath.each(doc,"./db:attribute") do |attribute|
@attribute||={}
@attribute[attribute.attributes['name']]=attribute.text
end
location=REXML::XPath.first(doc,"./db:location")
@location=location.text if location
@when={}
time=REXML::XPath.first(doc,"./gd:when")
if time
@when['startTime']=time.attributes['startTime']
@when['endTime']=time.attributes['endTime']
end
where=REXML::XPath.first(doc,"./gd:where")
@where=where.attributes['valueString'] if where
end
|