# File lib/jabber4r/protocol.rb, line 613
      def to_xml
        elem = XMLElement.new("iq", { "type"=>@type})
        elem.add_attribute("to" ,@to) if @to
        elem.add_attribute("id", @id) if @id
        elem.add_child("query").add_attribute("xmlns",@xmlns).add_data(@data.to_s)
        if @type=="error" then
          e=elem.add_child("error");
          e.add_attribute("code",@errorcode) if @errorcode
          e.add_data(@error) if @error
        end
        return elem.to_s
      end