Alas, this is also helpless. When I first looked at exodus CodeHe also laughed at why he had to do so many XML parsing work on his own. Only now can I find that I have to do it myself.
The XML Stream of XMPP is a piece of XML document. Therefore, the ideal situation is that if we receive a little XML, we will push it to a SAX Parser. Then we will get a sax event and hand over the accumulated XML to a DOM parser to parse Each XML stanza. The problem here is that there is no such SAX Parser that allows you to accept and do something over there. Generally, we will read the EOF and then strike. In addition, it is difficult for you to obtain the XML stanza start position and end position from the sax event so as to extract the XML and hand it to the DOM parser. The result is usually to skip the DOM parser from the sax event to complete the DOM assembly process.
My current practice is to strip the tokenizer part from the SAX Parser, and then parse the part that cannot be parsed by myself, and leave the part that cannot be parsed to the next time, and parse it together with the XML that will be pushed in next time. Then, based on the token information taken out by tokenizer, we assembled the simplified dom (only element and text, but XMPP is enough, not enough ). The final form is to provide a push method and five events, onstreambegin, onstreamend, onstanza, onstreamerror, and onparsererror.
At the beginning, I tried writing the code by myself. I found that the code was too ugly and it was better to write it by others. In any case, we finally avoided completely manual string comparison, which is much better than exodus.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.