Udostępnij za pośrednictwem


IXmlPullParser Interface

Definition

XML Pull Parser is an interface that defines parsing functionality provided in XMLPULL V1 API (visit this website to learn more about API and its implementations).

[Android.Runtime.Register("org/xmlpull/v1/XmlPullParser", "", "Org.XmlPull.V1.IXmlPullParserInvoker")]
public interface IXmlPullParser : Android.Runtime.IJavaObject, IDisposable, Java.Interop.IJavaPeerable
[<Android.Runtime.Register("org/xmlpull/v1/XmlPullParser", "", "Org.XmlPull.V1.IXmlPullParserInvoker")>]
type IXmlPullParser = interface
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Derived
Attributes
Implements

Remarks

XML Pull Parser is an interface that defines parsing functionality provided in XMLPULL V1 API (visit this website to learn more about API and its implementations).

There are following different kinds of parser depending on which features are set:<ul> <li><b>non-validating</b> parser as defined in XML 1.0 spec when FEATURE_PROCESS_DOCDECL is set to true <li><b>validating parser</b> as defined in XML 1.0 spec when FEATURE_VALIDATION is true (and that implies that FEATURE_PROCESS_DOCDECL is true) <li>when FEATURE_PROCESS_DOCDECL is false (this is default and if different value is required necessary must be changed before parsing is started) then parser behaves like XML 1.0 compliant non-validating parser under condition that <em>no DOCDECL is present</em> in XML documents (internal entites can still be defined with defineEntityReplacementText()). This mode of operation is intended <b>for operation in constrained environments</b> such as J2ME. </ul>

There are two key methods: next() and nextToken(). While next() provides access to high level parsing events, nextToken() allows access to lower level tokens.

The current event state of the parser can be determined by calling the getEventType() method. Initially, the parser is in the START_DOCUMENT state.

The method next() advances the parser to the next event. The int value returned from next determines the current parser state and is identical to the value returned from following calls to getEventType ().

Th following event types are seen by next()<dl> <dt>START_TAG<dd> An XML start tag was read. <dt>TEXT<dd> Text content was read; the text content can be retrieved using the getText() method. (when in validating mode next() will not report ignorable whitespace, use nextToken() instead) <dt>END_TAG<dd> An end tag was read <dt>END_DOCUMENT<dd> No more events are available </dl>

after first next() or nextToken() (or any other next*() method) is called user application can obtain XML version, standalone and encoding from XML declaration in following ways:<ul> <li><b>version</b>: getProperty(&quot;http://xmlpull.org/v1/doc/properties.html#xmldecl-version&quot;) returns String ("1.0") or null if XMLDecl was not read or if property is not supported <li><b>standalone</b>: getProperty(&quot;http://xmlpull.org/v1/doc/properties.html#xmldecl-standalone&quot;) returns Boolean: null if there was no standalone declaration or if property is not supported otherwise returns Boolean(true) if standalone="yes" and Boolean(false) when standalone="no" <li><b>encoding</b>: obtained from getInputEncoding() null if stream had unknown encoding (not set in setInputStream) and it was not declared in XMLDecl </ul>

A minimal example for using this API may look as follows:

import java.io.IOException;
            import java.io.StringReader;

            import org.xmlpull.v1.XmlPullParser;
            import org.xmlpull.v1.<a href="XmlPullParserException.html">XmlPullParserException</a>;
            import org.xmlpull.v1.<a href="XmlPullParserFactory.html">XmlPullParserFactory</a>;

            public class SimpleXmlPullApp
            {

                public static void main (String args[])
                    throws XmlPullParserException, IOException
                {
                    XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
                    factory.setNamespaceAware(true);
                    XmlPullParser xpp = factory.newPullParser();

                    xpp.<a href="#setInput">setInput</a>( new StringReader ( "&lt;foo>Hello World!&lt;/foo>" ) );
                    int eventType = xpp.getEventType();
                    while (eventType != XmlPullParser.END_DOCUMENT) {
                     if(eventType == XmlPullParser.START_DOCUMENT) {
                         System.out.println("Start document");
                     } else if(eventType == XmlPullParser.START_TAG) {
                         System.out.println("Start tag "+xpp.<a href="#getName()">getName()</a>);
                     } else if(eventType == XmlPullParser.END_TAG) {
                         System.out.println("End tag "+xpp.getName());
                     } else if(eventType == XmlPullParser.TEXT) {
                         System.out.println("Text "+xpp.<a href="#getText()">getText()</a>);
                     }
                     eventType = xpp.next();
                    }
                    System.out.println("End document");
                }
            }

The above example will generate the following output:

Start document
            Start tag foo
            Text Hello World!
            End tag foo
            End document

For more details on API usage, please refer to the quick Introduction available at http://www.xmlpull.org

Java documentation for org.xmlpull.v1.XmlPullParser.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Fields

FeatureProcessDocdecl

This feature determines whether the document declaration is processed.

FeatureProcessNamespaces

This feature determines whether the parser processes namespaces.

FeatureReportNamespaceAttributes

This feature determines whether namespace attributes are exposed via the attribute access methods.

FeatureValidation

If this feature is activated, all validation errors as defined in the XML 1.

NoNamespace

This constant represents the default namespace (empty string "")

Properties

AttributeCount

Returns the number of attributes of the current start tag, or -1 if the current event type is not START_TAG

ColumnNumber

Returns the current column number, starting from 0.

Depth

Returns the current depth of the element.

EventType

Returns the type of the current event (START_TAG, END_TAG, TEXT, etc.

Handle

Gets the JNI value of the underlying Android object.

(Inherited from IJavaObject)
InputEncoding

Returns the input encoding if known, null otherwise.

IsEmptyElementTag

Returns true if the current event is START_TAG and the tag is degenerated (e.g. <foobar/>).

IsWhitespace

Checks whether the current TEXT event contains only whitespace characters.

JniIdentityHashCode

Returns the value of java.lang.System.identityHashCode() for the wrapped instance.

(Inherited from IJavaPeerable)
JniManagedPeerState

State of the managed peer.

(Inherited from IJavaPeerable)
JniPeerMembers

Member access and invocation support.

(Inherited from IJavaPeerable)
LineNumber

Returns the current line number, starting from 1.

Name

For START_TAG or END_TAG events, the (local) name of the current element is returned when namespaces are enabled.

Namespace

Returns the namespace URI of the current element.

PeerReference

Returns a JniObjectReference of the wrapped Java object instance.

(Inherited from IJavaPeerable)
PositionDescription

Returns a short text describing the current parser state, including the position, a description of the current event and the data source if known.

Prefix

Returns the prefix of the current element.

Text

Returns the text content of the current event as String.

Types

This array can be used to convert the event type integer constants such as START_TAG or TEXT to to a string.

Methods

DefineEntityReplacementText(String, String)

Set new value for entity replacement text as defined in XML 1.0 Section 4.5 Construction of Internal Entity Replacement Text.

Disposed()

Called when the instance has been disposed.

(Inherited from IJavaPeerable)
DisposeUnlessReferenced()

If there are no outstanding references to this instance, then calls Dispose(); otherwise, does nothing.

(Inherited from IJavaPeerable)
Finalized()

Called when the instance has been finalized.

(Inherited from IJavaPeerable)
GetAttributeName(Int32)

Returns the local name of the specified attribute if namespaces are enabled or just attribute name if namespaces are disabled.

GetAttributeNamespace(Int32)

Returns the namespace URI of the attribute with the given index (starts from 0).

GetAttributePrefix(Int32)

Returns the prefix of the specified attribute Returns null if the element has no prefix.

GetAttributeType(Int32)

Returns the type of the specified attribute If parser is non-validating it MUST return CDATA.

GetAttributeValue(Int32)

Returns the given attributes value.

GetAttributeValue(String, String)

Returns the attributes value identified by namespace URI and namespace localName.

GetFeature(String)

Returns the current value of the given feature.

GetNamespace(String)

Returns the URI corresponding to the given prefix, depending on current state of the parser.

GetNamespaceCount(Int32)

Returns the numbers of elements in the namespace stack for the given depth.

GetNamespacePrefix(Int32)

Returns the namespace prefix for the given position in the namespace stack.

GetNamespaceUri(Int32)

Returns the namespace URI for the given position in the namespace stack If the position is out of range, an exception is thrown.

GetProperty(String)

Look up the value of a property.

GetTextCharacters(Int32[])

Returns the buffer that contains the text of the current event, as well as the start offset and length relevant for the current event.

IsAttributeDefault(Int32)

Returns if the specified attribute was not in input was declared in XML.

Next()

Get next parsing event - element content will be coalesced and only one TEXT event must be returned for whole element content (comments and processing instructions will be ignored and entity references must be expanded or exception must be thrown if entity reference can not be expanded).

NextTag()

Call next() and return event if it is START_TAG or END_TAG otherwise throw an exception.

NextText()

If current event is START_TAG then if next element is TEXT then element content is returned or if next event is END_TAG then empty string is returned, otherwise exception is thrown.

NextToken()

This method works similarly to next() but will expose additional event types (COMMENT, CDSECT, DOCDECL, ENTITY_REF, PROCESSING_INSTRUCTION, or IGNORABLE_WHITESPACE) if they are available in input.

Require(XmlPullParserNode, String, String)

Test if the current event is of the given type and if the namespace and name do match.

SetFeature(String, Boolean)

Use this call to change the general behaviour of the parser, such as namespace processing or doctype declaration handling.

SetInput(Reader)

Set the input source for parser to the given reader and resets the parser.

SetInput(Stream, String)

Sets the input stream the parser is going to process.

SetJniIdentityHashCode(Int32)

Set the value returned by JniIdentityHashCode.

(Inherited from IJavaPeerable)
SetJniManagedPeerState(JniManagedPeerStates) (Inherited from IJavaPeerable)
SetPeerReference(JniObjectReference)

Set the value returned by PeerReference.

(Inherited from IJavaPeerable)
SetProperty(String, Object)

Set the value of a property.

UnregisterFromRuntime()

Unregister this instance so that the runtime will not return it from future Java.Interop.JniRuntime+JniValueManager.PeekValue invocations.

(Inherited from IJavaPeerable)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)
NextAsync(IXmlPullParser)
NextTagAsync(IXmlPullParser)
NextTextAsync(IXmlPullParser)
NextTokenAsync(IXmlPullParser)

Applies to