CHECK_ATTRIB_UNIQ
protected static final boolean CHECK_ATTRIB_UNIQ
Should attribute uniqueness be checked for attributes
as in specified XML and NS specifications?
USE_QNAMEBUF
protected static final boolean USE_QNAMEBUF
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
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.
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.
getDepth
public int getDepth()
Returns the current depth of the element.
- getDepth in interface XmlPullParser
getEventType
public byte getEventType()
Returns the type of the current element (START_TAG, END_TAG, CONTENT, etc)
- getEventType in interface XmlPullParser
getLocalName
public String getLocalName()
Returns the local name of the current element
(current event must be START_TAG or END_TAG)
- getLocalName in interface XmlPullParser
getNamespaceUri
public String getNamespaceUri()
Returns the namespace URI of the current element
Returns null if not applicable
(current event must be START_TAG or END_TAG)
- getNamespaceUri in interface XmlPullParser
getPosDesc
public String getPosDesc()
Return string describing current position of parser in input stream.
- getPosDesc in interface XmlPullParser
getPrefix
public String getPrefix()
Returns the prefix of the current element
or null if elemet has no prefix.
(current event must be START_TAG or END_TAG)
- getPrefix in interface XmlPullParser
getQNameLocal
public String getQNameLocal(String qName)
Return local part of qname.
For example for 'xsi:type' it returns 'type'.
- getQNameLocal in interface XmlPullParser
getQNameUri
public String getQNameUri(String qName)
throws XmlPullParserException
Return uri part of qname.
It is depending on current state of parser to find
what namespace uri is mapped from namespace prefix.
For example for 'xsi:type' if xsi namespace prefix
was declared to 'urn:foo' it will return 'urn:foo'.
- getQNameUri in interface XmlPullParser
getRawName
public String getRawName()
Returns the raw name (prefix + ':' + localName) of the current element
(current event must be START_TAG or END_TAG)
- getRawName in interface XmlPullParser
next
public byte next()
throws XmlPullParserException,
IOException
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.
- next in interface XmlPullParser
readNode
public byte readNode(XmlNode node)
throws XmlPullParserException,
IOException
Read subtree into node: call readNodeWithoutChildren
and then parse subtree adding children
(values obtained with readXontent or readNodeWithoutChildren).
NOTE: parser must be on START_TAG event.
and all events will written into node!
- readNode in interface XmlPullParser
readNodeWithoutChildren
public void readNodeWithoutChildren(XmlNode node)
throws XmlPullParserException
Read node: it calls readStartTag and then if parser is namespaces
aware currently declared nemaspeces will be added
and defaultNamespace will be set.
NOTE: parser must be on START_TAG event.
and all events will written into node!
- readNodeWithoutChildren in interface XmlPullParser
reset
public void reset()
Reset parser state so it can be used to parse new
- reset in interface XmlPullParser
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.
- setAllowedMixedContent in interface XmlPullParser
setInput
public void setInput(Reader reader)
Reset parser and set new input.
- setInput in interface XmlPullParser
setInput
public void setInput(char[] buf)
Reset parser and set new input.
- setInput in interface XmlPullParser
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).
- setNamespaceAttributesReporting in interface XmlPullParser
skipNode
public byte skipNode()
throws XmlPullParserException,
IOException
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.
- skipNode in interface XmlPullParser