[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[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