Class PullParser

  • All Implemented Interfaces:
    XmlPullParser, XmlPullParserBufferControl, XmlPullParserEventPosition

    public class PullParser
    extends java.lang.Object
    implements XmlPullParser, XmlPullParserBufferControl, XmlPullParserEventPosition
    XML Pull Parser (XPP) allows to pull XML events from input stream. Advantages:
    • very simple pull interface - ideal for deserializing XML objects (like SOAP)
    • simple and efficient thin wrapper around Tokenizer class - when compared with using Tokenizer directly adds about 10% for big documents, maximum 50% more processing time for small documents
    • lightweight memory model - minimized memory allocation: element content and attributes are only read on explicit method calls, both StartTag and EndTag can be reused during parsing
    • small - total compiled size around 20K
    • by default supports namespaces parsing (can be switched off)
    • support for mixed content can be explicitly disabled
    Limitations:
    • this is beta version - may have still bugs :-)
    • does not parse DTD (recognizes only predefined entities)
    Author:
    Aleksander Slominski
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Attribute[] attrPos
      temporary array of current attributes
      protected int attrPosEnd
      index for last attribute in attrPos array
      protected int attrPosSize
      size of attrPos array
      protected static boolean CHECK_ATTRIB_UNIQ
      Should attribute uniqueness be checked for attributes as in specified XML and NS specifications?
      protected java.lang.String elContent
      Content of current element if in CONTENT state
      protected ElementContent[] elStack
      temprary array to keep ElementContent stack
      protected int elStackDepth
      how many elements are on elStack
      protected int elStackSize
      size of elStack array
      protected boolean emptyElement
      Have we read empty element?
      protected int eventEnd
      end position of current event in tokenizer biffer
      protected int eventStart
      start position of current event in tokenizer biffer
      protected java.util.Hashtable prefix2Ns
      mapping of names prefixes to uris
      protected boolean reportNsAttribs
      should parser report namespace xmlns* attributes ?
      protected boolean seenRootElement
      Have we seen root element
      protected byte state
      what is current event type as returned from next()?
      protected boolean supportNs
      should parser support namespaces?
      protected byte token
      what is current token returned from tokeizer
      protected Tokenizer tokenizer
      XML tokenizer that is doing actual tokenizning of input stream.
      protected static boolean USE_QNAMEBUF  
    • Constructor Summary

      Constructors 
      Constructor Description
      PullParser()
      Create instance of pull parser.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void ensureAttribs​(int size)
      Make sure that in attributes temporary array is enough space.
      protected void ensureCapacity​(int size)
      Make sure that we have enough space to keep element stack if passed size.
      int getBufferShrinkOffset()  
      int getColumnNumber()  
      int getContentLength()
      Return how big is content.
      int getDepth()
      Returns the current depth of the element.
      char[] getEventBuffer()
      NOTE: This may be internal buffer and is valud only until call to method next()- do NOT attempt modify !
      int getEventEnd()  
      int getEventStart()  
      byte getEventType()
      Returns the type of the current element (START_TAG, END_TAG, CONTENT, etc)
      int getHardLimit()  
      int getLineNumber()  
      java.lang.String getLocalName()
      Returns the local name of the current element (current event must be START_TAG or END_TAG)
      int getNamespacesLength​(int depth)  
      java.lang.String getNamespaceUri()
      Returns the namespace URI of the current element Returns null if not applicable (current event must be START_TAG or END_TAG)
      java.lang.String getPosDesc()
      Return string describing current position of parser in input stream.
      java.lang.String getPrefix()
      Returns the prefix of the current element or null if elemet has no prefix.
      java.lang.String getQNameLocal​(java.lang.String qName)
      Return local part of qname.
      java.lang.String getQNameUri​(java.lang.String qName)
      Return uri part of qname.
      java.lang.String getRawName()
      Returns the raw name (prefix + ':' + localName) of the current element (current event must be START_TAG or END_TAG)
      int getSoftLimit()  
      boolean isAllowedMixedContent()
      Is mixed element context allowed?
      boolean isBufferShrinkable()  
      boolean isNamespaceAttributesReporting()
      Is parser going to report namespace attributes (xmlns*) ?
      boolean isNamespaceAware()
      Is parser namespace aware?
      boolean isWhitespaceContent()
      Return true if just read CONTENT contained only white spaces.
      byte next()
      This is key method - it reads more from input stream and returns next event type (such as START_TAG, END_TAG, CONTENT).
      java.lang.String readContent()
      Return String that contains just read CONTENT.
      void readEndTag​(XmlEndTag etag)
      Read value of just read END_TAG into passed as argument EndTag.
      void readNamespacesPrefixes​(int depth, java.lang.String[] prefixes, int off, int len)
      Return namespace prefixes for element at depth
      void readNamespacesUris​(int depth, java.lang.String[] uris, int off, int len)
      Return namespace URIs for element at depth
      byte readNode​(XmlNode node)
      Read subtree into node: call readNodeWithoutChildren and then parse subtree adding children (values obtained with readXontent or readNodeWithoutChildren).
      void readNodeWithoutChildren​(XmlNode node)
      Read node: it calls readStartTag and then if parser is namespaces aware currently declared nemaspeces will be added and defaultNamespace will be set.
      void readStartTag​(XmlStartTag stag)
      Read value of just read START_TAG into passed as argument StartTag.
      void reset()
      Reset parser state so it can be used to parse new
      protected void resetState()  
      void setAllowedMixedContent​(boolean enable)
      Allow for mixed element content.
      void setBufferShrinkable​(boolean shrinkable)  
      void setHardLimit​(int value)  
      void setInput​(char[] buf)
      Reset parser and set new input.
      void setInput​(char[] buf, int off, int len)
      Set the input for parser.
      void setInput​(java.io.Reader reader)
      Reset parser and set new input.
      void setNamespaceAttributesReporting​(boolean enable)
      Make parser to report xmlns* attributes.
      void setNamespaceAware​(boolean awareness)
      Set support of namespaces.
      void setSoftLimit​(int value)  
      byte skipNode()
      If parser has just read start tag it allows to skip whoole subtree contined in this element.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CHECK_ATTRIB_UNIQ

        protected static final boolean CHECK_ATTRIB_UNIQ
        Should attribute uniqueness be checked for attributes as in specified XML and NS specifications?
        See Also:
        Constant Field Values
      • emptyElement

        protected boolean emptyElement
        Have we read empty element?
      • seenRootElement

        protected boolean seenRootElement
        Have we seen root element
      • elContent

        protected java.lang.String elContent
        Content of current element if in CONTENT state
      • tokenizer

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

        protected int eventStart
        start position of current event in tokenizer biffer
      • eventEnd

        protected int eventEnd
        end position of current event in tokenizer biffer
      • state

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

        protected byte token
        what is current token returned from tokeizer
      • supportNs

        protected boolean supportNs
        should parser support namespaces?
      • reportNsAttribs

        protected boolean reportNsAttribs
        should parser report namespace xmlns* attributes ?
      • prefix2Ns

        protected java.util.Hashtable prefix2Ns
        mapping of names prefixes to uris
      • attrPosEnd

        protected int attrPosEnd
        index for last attribute in attrPos array
      • attrPosSize

        protected int attrPosSize
        size of attrPos array
      • attrPos

        protected Attribute[] attrPos
        temporary array of current attributes
      • elStackDepth

        protected int elStackDepth
        how many elements are on elStack
      • elStackSize

        protected int elStackSize
        size of elStack array
      • elStack

        protected ElementContent[] elStack
        temprary array to keep ElementContent stack
    • Constructor Detail

      • PullParser

        public PullParser()
        Create instance of pull parser.