There are a couple of solutions to this:
1. Your XML is a single open stream. That is, there's an open tag right
at the start and an end tag and the end which signifies to close the
connection. The Jabber protocol works this way. You have to adopt
strict namespacing conventions and have to do some work with xml parsers.
2. Append each packet of XML data with a null terminator '/0'. Flash
XML handling works this way.
3. Insert length of XML packet information at the beginning for the XML
data.
Maarten Bosteels <[EMAIL PROTECTED]> a écrit :
Hi,
We use mina for transport and xmlbeans (http://xmlbeans.apache.org)
to parse and generate xml documents.
Our ProtocolDecoder just reads an array of bytes
and the ProtocolHandler passes these bytes on to the xmlparser.
The protocol (EPP) is pretty simple:
* 4 bytes indicating the total length of the message
* (length - 4) bytes of xml data
Academic question: If your protocol doesn't have a length header and
you don't know the
byte encoding used by the incoming xml, how can you know when a
message is complete ?
Maarten,
I use Mina (in Belgium too, for info) for a binary protocol, and we
add 4 bytes
too. This makes our protocol more robust, and decoding easier.
J-F
Maarten
Chris Allen wrote:
Hi,
I ended up using Jdom for paring the XML in my proxy server for Jabber
using MINA. It worked very well. Basically you can create a
ProtocolCodecFactory that uses a custom ProtocolDecoder. The decoder
will have to overwrite the decode() method where it will convert the
ByteBuffer that it receives into an org.jdom.Document instance. You
can either do the parsing of the XML there or do it in your
IoHandlerAdapter's messageReceived() method.
There is a good example of using a ProtocolCodecFactory for converting
the messages to Strings on the MINA website; it's basically the same
thing, except you convert it into either a Jdom Document like I'm
doing or one of the others that Vinod suggested. Take a look at the
package org.apache.mina.filter.codec.textline for an example:
http://directory.apache.org/subprojects/network/xref/org/apache/mina/filter/codec/textline/package-summary.html
I hope that helps.
-Chris
On 1/6/06, Vinod Panicker <[EMAIL PROTECTED]> wrote:
On 1/6/06, [EMAIL PROTECTED]
<[EMAIL PROTECTED]> wrote:
Hi all
Is there any source code that implement XML parsing for Mina ?
my Aim is to implement an XML parsing (as a decoder) that
transform XML in
object and send this objects to the handler.
Has anyone see some sample about that ?
Might sound silly, but have you considered using SAX / DOM / XPath for
your XML parsing? That will give you ready made objects that you can
pass to your handler.
Regards,
Vinod.