开发者

Java, from XMPP server response string to XML Document

I have a client which connects to a XMPP Server, and the server send me the answer

<?xml version="1.0"?><stream:stream id="119B61FB" from="chat.facebook.com" version="1.0" xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" xml:lang="en">

I try to create an XMLDocument with the Document class:

try {
        parser = factory.newDocumentBuilder();
        d = parser.parse(new ByteArrayInputStream(cleanXMLString.getBytes("UTF-8")));
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(XMPPManager.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {开发者_如何学Go
        Logger.getLogger(XMPPManager.class.getName()).log(Level.SEVERE, null, ex);
    }

but I get the error:

org.xml.sax.SAXParseException: XML document structures must start and end within the same entity of the SAXException.

There is a way to disable this restriction, because it is normal that the document is not closed by a </stream:stream> tag?


This is the first of many questions that you will have implementing XMPP.

You'll need an incremental XML parser, like James Clark's XP. Even better would be to use an existing XMPP library for Java from the list on xmpp.org.


Try using Smack for communications between your server and client. It will take care of all the low level communications for you and allow you to program at a more functional abstraction level.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜