Le 5/27/12 11:58 PM, Niklas Gustavsson a écrit :
On Thu, May 24, 2012 at 7:39 PM, Emmanuel Lécharny<[email protected]> wrote:
as I was looking for a decent non blocking XML parser, I was directed to
Aalto FasterXML (http://wiki.fasterxml.com/AaltoHome), which is also an AL
2.0 software !
I had a look at Aalto before writing what is now nbxml. At that time
is was GPL and thus not something we could use.
Yep. They changed ot to ASL 2.0, which is good for us.
I played a bit with it this week-end. It's not perfect, and the
documentation is pretty minimal (well, hmmm, on par with MINA :) but
it's quite usable.
Here is a small test I wrote that leverage the resuming capacity of this
parser :
public void testSplitXML() throws Exception {
AsyncXMLInputFactory f = new InputFactoryImpl();
String XML =
"<?xml version='1.0' ?>" +
"<xml>" +
" <myTag> <!-- comment-";
String XML2 =
"->" +
" Test" +
" </myTag>" +
" <at";
String XML3 =
"tr val=\"5\">" +
" </attr>" +
"</xml>";
AsyncXMLStreamReader sr = f.createAsyncXMLStreamReader();
AsyncReaderWrapper reader = new AsyncReaderWrapper(sr, 1, XML);
int token = 0;
boolean endDocument = false;
token = reader.nextToken2();
do {
if ( reader.needMoreInput() ) {
break;
}
endDocument = printToken( sr, token );
token = reader.nextToken2();
}
while( token != AsyncXMLStreamReader.EVENT_INCOMPLETE );
reader.feedMoreInput( XML2 );
do {
endDocument = printToken( sr, token );
if ( endDocument ) {
break;
}
token = reader.nextToken2();
}
while( token != AsyncXMLStreamReader.EVENT_INCOMPLETE );
reader.feedMoreInput( XML3 );
do {
endDocument = printToken( sr, token );
if ( endDocument ) {
break;
}
token = reader.nextToken2();
}
while( token != AsyncXMLStreamReader.EVENT_INCOMPLETE );
assertTrue( endDocument );
}
It produces this output :
Start document
Start Element 'xml'
Char ' '
Start Element 'myTag'
Char ' '
Comment ' comment'
Char ' Test '
End Element 'myTag'
Char ' '
Start Element 'attr'
Attribute N°1 <name = 'val', value = '5'>
Char ' '
End Element 'attr'
End Element 'xml'
End document
done=========
(The printToken method is pretty minimalistic at this point, it just
dumps the data)
The biggest advantage of this parser is that it takes care of nameSpace,
entities, and a few other XML crazyness. It also seems to be fast.
Still, it's not yet a released version, but there is definitively some
potential.
I'll try to write some example in MINA 3 with this tool.
--
Regards,
Cordialement,
Emmanuel Lécharny
www.iktek.com