public static <T> int writeTo(final OutputStream out, final T message,
            final Schema<T> schema, final LinkedBuffer buffer) throws IOException
    {
        if (buffer.start != buffer.offset)
            throw new IllegalArgumentException("Buffer previously used and had not been reset.");

        final XmlXOutput output = new XmlXOutput(buffer, out, schema);

        final String name = schema.messageName();

        // header and start root element
        output.tail = output.sink.writeByte(XmlXOutput.END_TAG, output,
                output.sink.writeStrAscii(name, output,
                        output.sink.writeByte(XmlXOutput.START_TAG, output,
                                output.sink.writeByteArray(HEADER, output, output.tail))));

        schema.writeTo(output, message);

        // end root element
        output.tail = output.sink.writeByte(XmlXOutput.END_TAG, output,
                output.sink.writeStrAscii(name, output,
                        output.sink.writeByteArray(XmlXOutput.START_SLASH_TAG, output, output.tail)));

        LinkedBuffer.writeTo(out, buffer);

        return output.size;
    }
Serializes the {@code message} into an {@link OutputStream} using the given schema.

@return the size of the message
protostuff-xml/src/main/java/io/protostuff/XmlXIOUtil.java