def to_hash(array = XArray, unsanitize_p = false)
if( @hash )
return @hash
end
ary = array[]
@children.each{|child|
if( child.is_a?(XNode) )
ary.push(child.to_hash(array,unsanitize_p))
else
text = child.to_s
if( ary[-1].is_a?(String) )
ary[-1].concat(text)
else
if( unsanitize_p )
text = unsanitize(text)
end
ary.push(text.dup)
end
end
}
@attrs.each{|attr,val|
if( unsanitize_p )
val = unsanitize(val)
end
ary.push({'@'+attr => val})
}
if( ary.size == 1 )
ary = ary[0]
end
case @option[:type]
when 'array'
ary = Array[*ary]
when 'hash'
ary = eval_action("hash()", ary, nil)
when 'int'
ary = ary.to_i
when 'float'
ary = ary.to_f
when 'string'
ary = ary.to_s
end
if( @name )
@hash = {@name => ary}
else
case ary
when Hash
@hash = ary
else
@hash = {}
ary.each{|h|
if( h.is_a?(Hash) )
h.each{|key,val|
@hash[key] = val
}
end
}
end
end
@hash
end