hi,
it is interesting coincidence that you write about it - i was planning to
do the same to investigate how to provide alternative XPP2 implementation
using Xerces2 XNI pull interface - i have separated API interfaces from
implementation(s) by use of JAXP-like factory mechanism. and it would be
really nice to have more than one implementation :-)
----- Original Message -----
From: "Ted Leung" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, August 14, 2001 2:34 AM
Subject: Re: [Xerces2] Pull Parsing
> I've looked at XPP and KXML as alternative pull parsers.
>
> XPP returns an int based typecode and then you get to call one of
> a number of methods and supply a data struture to be filled in. It's
very
> C like, and because of that, it's likely to be efficient in nice ways.
>
please take a look on XPP2 which is a major API revision of XPP.
when you mention this tradeoff you may be interested to find out that
i had the same problem and even come up with nice solution which is
very OO but it does not add much value to API (and in my opinion
adding extra class to represent event is complicating API and making
jar file bigger...).
below is XmlPullParserEvent class that could be returned for pp.next()
instead of byte (notice that user code won't change much if it is byte of
XmlPullParserEvent) for typical usage:
XmlPullParser pp = factory.newPullParser();
pp.setInput(new Reader(...));
//XmlPullParserEvent eventType; //using new approach
byte eventType; //and current style
eventType = pp.next();
if(eventType == XmlPullParser.CONTENT) ...
thanks,
alek
ps. here is how XmlPullParserEvent could look (notice that state is
modeled as singletons):
/**
* Utility class to nicely describe the state of XML Pull Parser.
*
* @author Aleksander Slominski [[EMAIL PROTECTED]]
*/
public class XmlPullParserEvent {
/** parsing is finished - we are at the end of input */
public static final XmlPullParserEvent END_DOCUMENT =
new XmlPullParserEvent("END_DOCUMENT");
/** start tag was just read */
public static final XmlPullParserEvent START_TAG =
new XmlPullParserEvent("START_TAG");
/** end tag was just read */
public static final XmlPullParserEvent END_TAG =
new XmlPullParserEvent("END_TAG");
/** element content was just read */
public static final XmlPullParserEvent CONTENT =
new XmlPullParserEvent("CONTENT");
protected XmlPullParserEvent(String name) {
this.name = name;
}
//TODO equals, hashCode
public final String toString() {
return name;
}
public static XmlPullParserEvent parse(String name) {
XmlPullParserEvent xs = null;
if(END_DOCUMENT.name.equals(name)) return END_DOCUMENT;
if(START_TAG.name.equals(name)) return START_TAG;
if(END_TAG.name.equals(name)) return END_TAG;
if(CONTENT.name.equals(name)) return CONTENT;
if(xs == null) throw new IllegalArgumentException
("unknown xml state: "+name);
return xs;
}
protected String name;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]