[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [JDEV] XML protocol question




	I am working with JabberBeans and intend to check in the first fully
functional version within a day or so.  I use an XML parser in Java to do
the trick, naturally, and here's what worked for me:

	I fully read the packet off the line, build a String, and pass it over to
an XML-aware ProtocolConsumer, which understand the Jabber protocol and
builds JabberBean Packets. From here it gets passed to an XML-parser aware
class which currently relies on IBM's XML4J, but could be easily switched to
something else if need be. This XMLParser class does a simple check to see
whether it is parsable by an Non-Validating (for the time being) parser
(using DOM, not SAX.) If it is not, it attempts to make it so by
ap-or-prepending any required information. So far, I have found that simply
prepending "<? xml version=...?>" type identifiers is all it needs to create
a Document object. JabberBeans passes this back to the ProtocolConsumer
which builds a Packet (MessagePacket,RosterPacket,StatusPacket, etc.) from
the Document.

	Thus, this:

> <message>
>         <to>jeremie</to>
>         <say>test</say>
> </message>

	becomes this:

> <?xml version="1.0"?>
> <message>
>         <to>jeremie</to>
>         <say>test</say>
> </message>


	Does this help at all? The JabberBeans code will go in very soon and I can
send it to you ahead of time if you are interested.


Patrick McCuller




> -----Original Message-----
> From: owner-jdev@jabber.org [mailto:owner-jdev@jabber.org]On Behalf Of
> Sean McCullough
> Sent: Monday, July 26, 1999 6:56 PM
> To: jdev@jabber.org
> Subject: [JDEV] XML protocol question
>
>
> I've been trying to implement a Jabber protocol stack in java using the
> org.xml.sax parser package. (this is not part of the JabberBeans
> project btw)
>
> Is there any reason not to wrap top-level elements in the Jabber
> client-server protocol in full xml document tags (aside from the size
> increase)?  I'm running into some design problems where I can't take
> advantage of SAX/DOM the way I want to.  I'm trying to read in a series
> of packets, blocking the requesting thread when necessary.  Currently
> I'm using the SAX DocuemntHandler callback methods to figure out when a
> packet is done reading/parsing so I can wake up the reader thread if
> it's blocking.  This is getting tricky because I can't decide if the
> PacketReader should interpret every element (in which case it must know
> more about Packet subclasses than it should (ick)), or if Packet
> classes should parse their own content (meaning Packet must implement
> DocumentHandler (ick)).  I'd rather use the DOM with Sun's JavaBean
> support, but it's not going to finish parsing anything in Jabber
> session until it reaches the outer </jabber> element which (I believe)
> currently means your session is over :-/
>
> so the example at
> http://www.jabber.org/download/latest/doc/protocol/client2server.txt
>
> would look like:
>
> <?xml version="1.0"?>
> <jabber version="name/os version/version" protocol="19990324">
>
> <login>
>         <user>jeremie</user>
>         <pass>Ph0niks</pass>
>         <nick>jabalot</nick>
> </login>
>
> </jabber>
>
> <jabber version="name/os version/version" protocol="19990324">
>
> <message>
>         <to>jeremie</to>
>         <say>test</say>
> </message>
> </jabber>
>
> <jabber version="name/os version/version" protocol="19990324">
>
> <message>
>         <to>someone</to>
>         <to name='Jenny(work)'>jenny</to>
>         <to>jeremie</to>
>         <to name='HAhah!'>safdsgh@asdfg.asdfasdf</to>
>         <thread>sdfa</thread>
>         <priority>1</priority>
>         <subject>Did you see that?</subject>
>         <say>asdgf asdfkjasgoijqwert asdgaldgjkas</say>
> </message>
>
> </jabber>
>
> ...
>
>
> Am I going about this the wrong way?  I know it looks like I'm asking
> for a lot of unnecessary overhead but I can't think of a good way to
> use the available XML tools without it.
>
> I suppose a workaround would be to read past the opening jabber element
> before handing the InputStream  over to the DOM, but that would
> probably throw exceptions for the lack of <? xml ?> tag and the
> unexpected ending </jabber>
>
> Has anyone else tried to use DOM or SAX to implement an XML protocol?
> I haven't looked at IBM's Java XML parser yet so it might better suit
> what I'm trying to do than Sun's parser.
>
> -Sean McCullough
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>
>