# File lib/jabber4r/protocol.rb, line 844
844:       def to_xml
845:         @thread = Jabber.gen_random_thread if @thread.nil? and (not @is_reply)
846:         elem = XMLElement.new("message", {"to"=>@to, "type"=>@type})
847:         elem.add_attribute("id", @id) if @id
848:         elem.add_child("thread").add_data(@thread) if @thread
849:         elem.add_child("subject").add_data(@subject) if @subject
850:         elem.add_child("body").add_data(@body) if @body
851:         if @xhtml then
852:           t=elem.add_child("xhtml").add_attribute("xmlns","http://www.w3.org/1999/xhtml")
853:           t.add_child("body").add_data(@xhtml)
854:         end
855:         if @type=="error" then
856:           e=elem.add_child("error");
857:           e.add_attribute("code",@errorcode) if @errorcode
858:           e.add_data(@error) if @error
859:         end
860:         elem.add_child("x").add_attribute("xmlns", "jabber:x:oob").add_data(@oobData) if @oobData
861:         elem.add_xml(@x.to_s) if @x
862:         return elem.to_s
863:       end