def to_xml
@thread = Jabber.gen_random_thread if @thread.nil? and (not @is_reply)
elem = XMLElement.new("message", {"to"=>@to, "type"=>@type})
elem.add_attribute("id", @id) if @id
elem.add_child("thread").add_data(@thread) if @thread
elem.add_child("subject").add_data(@subject) if @subject
elem.add_child("body").add_data(@body) if @body
if @xhtml then
t=elem.add_child("xhtml").add_attribute("xmlns","http://www.w3.org/1999/xhtml")
t.add_child("body").add_data(@xhtml)
end
if @type=="error" then
e=elem.add_child("error");
e.add_attribute("code",@errorcode) if @errorcode
e.add_data(@error) if @error
end
elem.add_child("x").add_attribute("xmlns", "jabber:x:oob").add_data(@oobData) if @oobData
elem.add_xml(@x.to_s) if @x
return elem.to_s
end