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
|
# File 'lib/enterprise/sexp_hacks.rb', line 4
def to_xml doc = Document.new, parent = doc.root = Node.new('s', doc)
each do |node|
case node
when Sexp
new_parent = Node.new('s', parent.document)
parent.add_child new_parent
node.to_xml doc, new_parent
else
name = node.to_s
if node.to_s.empty? || node.to_s !~ /^[A-Za-z]+$/
name = 'special'
end
n = Node.new(name, parent.document)
n['type'] = node.class.name
if Regexp === node
n['value'] = [Marshal.dump(node)].pack('m')
else
n['value'] = node.to_s
end
parent << n
end
end
doc
end
|