Class FastInfosetReader

All Implemented Interfaces:
OctetBufferListener, XMLReader, XMLStreamConstants, XMLStreamReader, FastInfosetParser, FastInfosetStreamReader

public final class FastInfosetReader extends StAXDocumentParser implements XMLReader

XMLReader provides a high-level streaming parser interface for reading XML documents.

The next() method is used to read events from the XML document.

Each time it is called, next() returns the new state of the reader.

Possible states are: BOF, the initial state, START, denoting the start tag of an element, END, denoting the end tag of an element, CHARS, denoting the character content of an element, PI, denoting a processing instruction, EOF, denoting the end of the document.

Depending on the state the reader is in, one or more of the following query methods will be meaningful: StAXDocumentParser.getName(), getURI(), StAXDocumentParser.getLocalName(), getAttributes(), getValue().

Elements visited by a XMLReader are tagged with unique IDs. The ID of the current element can be found by calling getElementId().

A XMLReader is always namespace-aware, and keeps track of the namespace declarations which are in scope at any time during streaming. The StAXDocumentParser.getURI(java.lang.String) method can be used to find the URI associated to a given prefix in the current scope.

XMLReaders can be created using a XMLReaderFactory.

Some utility methods, nextContent() and nextElementContent() make it possible to ignore whitespace and processing instructions with minimum impact on the client code.

Similarly, the skipElement() and skipElement(int elementId) methods allow to skip to the end tag of an element ignoring all its content.

Finally, the recordElement() method can be invoked when the XMLReader is positioned on the start tag of an element to record the element's contents so that they can be played back later.

Author:
JAX-RPC Development Team
See Also:
  • Constructor Details

    • FastInfosetReader

      public FastInfosetReader(InputStream is)
      Initialize a FastInfosetReader instance. Note that reset() is called by constructor in base class.
  • Method Details

    • reset

      public void reset()
      Description copied from class: Decoder
      Reset the decoder for reuse decoding another XML infoset.
      Overrides:
      reset in class StAXDocumentParser
    • next

      public int next()
      Return the next state of the XMLReader. The return value is one of: START, END, CHARS, PI, EOF.
      Specified by:
      next in interface XMLReader
      Specified by:
      next in interface XMLStreamReader
      Overrides:
      next in class StAXDocumentParser
    • nextElementContent

      public int nextElementContent()
      Description copied from interface: XMLReader
      Return the next state of the XMLReader.

      Whitespace character content, processing instructions are ignored. Non-whitespace character content triggers an exception.

      The return value is one of: START, END, EOF.

      Specified by:
      nextElementContent in interface XMLReader
    • nextContent

      public int nextContent()
      Specified by:
      nextContent in interface XMLReader
    • getState

      public int getState()
      Return the current state of the XMLReader.
      Specified by:
      getState in interface XMLReader
    • getURI

      public String getURI()
      Return the current URI.

      Meaningful only when the state is one of: START, END.

      Specified by:
      getURI in interface XMLReader
    • getAttributes

      public Attributes getAttributes()
      Return the current attribute list.

      Meaningful only when the state is one of: START.

      The returned Attributes object belong to the XMLReader and is only guaranteed to be valid until the next() method is called, directly or indirectly.

      Specified by:
      getAttributes in interface XMLReader
    • getValue

      public String getValue()
      Return the current value.

      Meaningful only when the state is one of: CHARS, PI.

      Specified by:
      getValue in interface XMLReader
    • getElementId

      public int getElementId()
      Return the current element ID.
      Specified by:
      getElementId in interface XMLReader
    • getLineNumber

      public int getLineNumber()
      Return the current line number.

      Due to aggressive parsing, this value may be off by a few lines.

      Specified by:
      getLineNumber in interface XMLReader
    • recordElement

      public XMLReader recordElement()
      Records the current element and leaves the reader positioned on its end tag.

      The XMLReader must be positioned on the start tag of the element. The returned reader will play back all events starting with the start tag of the element and ending with its end tag.

      Specified by:
      recordElement in interface XMLReader
    • skipElement

      public void skipElement()
      Skip all nodes up to the end tag of the element with the current element ID.
      Specified by:
      skipElement in interface XMLReader
    • skipElement

      public void skipElement(int elementId)
      Skip all nodes up to the end tag of the element with the given element ID.
      Specified by:
      skipElement in interface XMLReader
    • close

      public void close()
      Close the XMLReader.

      All subsequent calls to next() will return EOF.

      Specified by:
      close in interface XMLReader
      Specified by:
      close in interface XMLStreamReader
      Overrides:
      close in class StAXDocumentParser