public String getChildElementXML() {
        StringBuilder buf = new StringBuilder();

        buf.append("<query xmlns=\"http://jabber.org/protocol/bytestreams\"");
        if (this.getType().equals(IQ.Type.SET)) {
            if (getSessionID() != null)
                buf.append(" sid=\"").append(getSessionID()).append("\"");
            if (getMode() != null)
                buf.append(" mode = \"").append(getMode()).append("\"");
            buf.append(">");
            if (getToActivate() == null) {
                for (StreamHost streamHost : getStreamHosts()) {
                    buf.append(streamHost.toXML());
                }
            }
            else {
                buf.append(getToActivate().toXML());
            }
        }
        else if (this.getType().equals(IQ.Type.RESULT)) {
            buf.append(">");
            if (getUsedHost() != null)
                buf.append(getUsedHost().toXML());
            // A result from the server can also contain stream hosts
            else if (countStreamHosts() > 0) {
                for (StreamHost host : streamHosts) {
                    buf.append(host.toXML());
                }
            }
        }
        else {
            return null;
        }
        buf.append("</query>");

        return buf.toString();
    }