org.gjt.xpp.impl.pullparser

Class PullParser

public class PullParser extends Object implements XmlPullParser, XmlPullParserBufferControl, XmlPullParserEventPosition

XML Pull Parser (XPP) allows to pull XML events from input stream. Advantages: Limitations:

Author: Aleksander Slominski

Field Summary
protected Attribute[]attrPos
temporary array of current attributes
protected intattrPosEnd
index for last attribute in attrPos array
protected intattrPosSize
size of attrPos array
protected static booleanCHECK_ATTRIB_UNIQ
Should attribute uniqueness be checked for attributes as in specified XML and NS specifications?
protected StringelContent
Content of current element if in CONTENT state
protected ElementContent[]elStack
temprary array to keep ElementContent stack
protected intelStackDepth
how many elements are on elStack
protected intelStackSize
size of elStack array
protected booleanemptyElement
Have we read empty element?
protected inteventEnd
end position of current event in tokenizer biffer
protected inteventStart
start position of current event in tokenizer biffer
protected Hashtableprefix2Ns
mapping of names prefixes to uris
protected booleanreportNsAttribs
should parser report namespace xmlns* attributes ?
protected booleanseenRootElement
Have we seen root element
protected bytestate
what is current event type as returned from next()?
protected booleansupportNs
should parser support namespaces?
protected bytetoken
what is current token returned from tokeizer
protected Tokenizertokenizer
XML tokenizer that is doing actual tokenizning of input stream.
protected static booleanUSE_QNAMEBUF
Constructor Summary
PullParser()
Create instance of pull parser.
Method Summary
protected voidensureAttribs(int size)
Make sure that in attributes temporary array is enough space.
protected voidensureCapacity(int size)
Make sure that we have enough space to keep element stack if passed size.
intgetBufferShrinkOffset()
intgetColumnNumber()
intgetContentLength()
intgetDepth()
char[]getEventBuffer()
intgetEventEnd()
intgetEventStart()
bytegetEventType()
intgetHardLimit()
intgetLineNumber()
StringgetLocalName()
intgetNamespacesLength(int depth)
StringgetNamespaceUri()
StringgetPosDesc()
Return string describing current position of parser in input stream.
StringgetPrefix()
StringgetQNameLocal(String qName)
StringgetQNameUri(String qName)
StringgetRawName()
intgetSoftLimit()
booleanisAllowedMixedContent()
booleanisBufferShrinkable()
booleanisNamespaceAttributesReporting()
booleanisNamespaceAware()
booleanisWhitespaceContent()
Return true if just read CONTENT contained only white spaces.
bytenext()
This is key method - it reads more from input stream and returns next event type (such as START_TAG, END_TAG, CONTENT). or END_DOCUMENT if no more input.
StringreadContent()
Return String that contains just read CONTENT.
voidreadEndTag(XmlEndTag etag)
Read value of just read END_TAG into passed as argument EndTag.
voidreadNamespacesPrefixes(int depth, String[] prefixes, int off, int len)
Return namespace prefixes for element at depth
voidreadNamespacesUris(int depth, String[] uris, int off, int len)
Return namespace URIs for element at depth
bytereadNode(XmlNode node)
voidreadNodeWithoutChildren(XmlNode node)
voidreadStartTag(XmlStartTag stag)
Read value of just read START_TAG into passed as argument StartTag.
voidreset()
Reset parser state so it can be used to parse new
protected voidresetState()
voidsetAllowedMixedContent(boolean enable)
Allow for mixed element content.
voidsetBufferShrinkable(boolean shrinkable)
voidsetHardLimit(int value)
voidsetInput(Reader reader)
Reset parser and set new input.
voidsetInput(char[] buf)
Reset parser and set new input.
voidsetInput(char[] buf, int off, int len)
voidsetNamespaceAttributesReporting(boolean enable)
Make parser to report xmlns* attributes.
voidsetNamespaceAware(boolean awareness)
Set support of namespaces.
voidsetSoftLimit(int value)
byteskipNode()
If parser has just read start tag it allows to skip whoole subtree contined in this element.

Field Detail

attrPos

protected Attribute[] attrPos
temporary array of current attributes

attrPosEnd

protected int attrPosEnd
index for last attribute in attrPos array

attrPosSize

protected int attrPosSize
size of attrPos array

CHECK_ATTRIB_UNIQ

protected static final boolean CHECK_ATTRIB_UNIQ
Should attribute uniqueness be checked for attributes as in specified XML and NS specifications?

elContent

protected String elContent
Content of current element if in CONTENT state

elStack

protected ElementContent[] elStack
temprary array to keep ElementContent stack

elStackDepth

protected int elStackDepth
how many elements are on elStack

elStackSize

protected int elStackSize
size of elStack array

emptyElement

protected boolean emptyElement
Have we read empty element?

eventEnd

protected int eventEnd
end position of current event in tokenizer biffer

eventStart

protected int eventStart
start position of current event in tokenizer biffer

prefix2Ns

protected Hashtable prefix2Ns
mapping of names prefixes to uris

reportNsAttribs

protected boolean reportNsAttribs
should parser report namespace xmlns* attributes ?

seenRootElement

protected boolean seenRootElement
Have we seen root element

state

protected byte state
what is current event type as returned from next()?

supportNs

protected boolean supportNs
should parser support namespaces?

token

protected byte token
what is current token returned from tokeizer

tokenizer

protected Tokenizer tokenizer
XML tokenizer that is doing actual tokenizning of input stream.

USE_QNAMEBUF

protected static final boolean USE_QNAMEBUF

Constructor Detail

PullParser

public PullParser()
Create instance of pull parser.

Method Detail

ensureAttribs

protected void ensureAttribs(int size)
Make sure that in attributes temporary array is enough space.

ensureCapacity

protected void ensureCapacity(int size)
Make sure that we have enough space to keep element stack if passed size.

getBufferShrinkOffset

public int getBufferShrinkOffset()

getColumnNumber

public int getColumnNumber()

getContentLength

public int getContentLength()

getDepth

public int getDepth()

getEventBuffer

public char[] getEventBuffer()

getEventEnd

public int getEventEnd()

getEventStart

public int getEventStart()

getEventType

public byte getEventType()

getHardLimit

public int getHardLimit()

getLineNumber

public int getLineNumber()

getLocalName

public String getLocalName()

getNamespacesLength

public int getNamespacesLength(int depth)

getNamespaceUri

public String getNamespaceUri()

getPosDesc

public String getPosDesc()
Return string describing current position of parser in input stream.

getPrefix

public String getPrefix()

getQNameLocal

public String getQNameLocal(String qName)

getQNameUri

public String getQNameUri(String qName)

getRawName

public String getRawName()

getSoftLimit

public int getSoftLimit()

isAllowedMixedContent

public boolean isAllowedMixedContent()

isBufferShrinkable

public boolean isBufferShrinkable()

isNamespaceAttributesReporting

public boolean isNamespaceAttributesReporting()

isNamespaceAware

public boolean isNamespaceAware()

isWhitespaceContent

public boolean isWhitespaceContent()
Return true if just read CONTENT contained only white spaces.

next

public byte next()
This is key method - it reads more from input stream and returns next event type (such as START_TAG, END_TAG, CONTENT). or END_DOCUMENT if no more input.

This is simple automata (in pseudo-code):

 byte next() {
    while(state != END_DOCUMENT) {
      token = tokenizer.next();  // get next XML token
      switch(token) {

      case Tokenizer.END_DOCUMENT:
        return state = END_DOCUMENT

      case Tokenizer.CONTENT:
        // check if content allowed - only inside element
        return state = CONTENT

     case Tokenizer.ETAG_NAME:
        // popup element from stack - compare if matched start and end tag
        // if namespaces supported restore namespaces prefix mappings
        return state = END_TAG;

      case Tokenizer.STAG_NAME:
        // create new  element push it on stack
        // process attributes (including namespaces)
        // set emptyElement = true; if empty element
        // check atribute uniqueness (including nmespacese prefixes)
        return state = START_TAG;

      }
    }
 }
 

Actual parsing is more complex especilly for start tag due to dealing with attributes reported separately from tokenizer and declaring namespace prefixes and uris.

readContent

public String readContent()
Return String that contains just read CONTENT.

readEndTag

public void readEndTag(XmlEndTag etag)
Read value of just read END_TAG into passed as argument EndTag.

readNamespacesPrefixes

public void readNamespacesPrefixes(int depth, String[] prefixes, int off, int len)
Return namespace prefixes for element at depth

readNamespacesUris

public void readNamespacesUris(int depth, String[] uris, int off, int len)
Return namespace URIs for element at depth

readNode

public byte readNode(XmlNode node)

readNodeWithoutChildren

public void readNodeWithoutChildren(XmlNode node)

readStartTag

public void readStartTag(XmlStartTag stag)
Read value of just read START_TAG into passed as argument StartTag.

reset

public void reset()
Reset parser state so it can be used to parse new

resetState

protected void resetState()

setAllowedMixedContent

public void setAllowedMixedContent(boolean enable)
Allow for mixed element content. Enabled by default. When disbaled element must containt either text or other elements.

setBufferShrinkable

public void setBufferShrinkable(boolean shrinkable)

setHardLimit

public void setHardLimit(int value)

setInput

public void setInput(Reader reader)
Reset parser and set new input.

setInput

public void setInput(char[] buf)
Reset parser and set new input.

setInput

public void setInput(char[] buf, int off, int len)

setNamespaceAttributesReporting

public void setNamespaceAttributesReporting(boolean enable)
Make parser to report xmlns* attributes. Disabled by default. Only meaningful when namespaces are enabled (when namespaces are disabled all attributes are always reported).

setNamespaceAware

public void setNamespaceAware(boolean awareness)
Set support of namespaces. Disabled by default.

setSoftLimit

public void setSoftLimit(int value)

skipNode

public byte skipNode()
If parser has just read start tag it allows to skip whoole subtree contined in this element. Returns when encounters end tag matching the start tag.
Copyright (c) 2003 IU Extreme! Lab http://www.extreme.indiana.edu/ All Rights Reserved.

Note this package is deprecated by XPP3 that implements XmlPull API