Class SMFlatteningCursor


public class SMFlatteningCursor extends SMInputCursor
Default implementation of generic flat (non-scoped) cursor; cursor that traverse all descendants (children and grandchildren) of a start element.

Differences to SMHierarchicCursor are:

  • Flat cursors return XMLStreamConstants.END_ELEMENT nodes (except for the one that closes the outermost level), unless filtered out by the filter, whereas the nested cursor automatically leaves those out.
  • Flat cursors can not have child/descendant cursors
  • Constructor Details

  • Method Details

    • getParentCount

      public int getParentCount()
      Description copied from class: SMInputCursor
      Number of parent elements that the token/event cursor points to has, if it points to one. If not, either most recent valid parent count (if cursor is closed), or the depth that it will have once is is advanced. One practical result is that a nested cursor instance will always have a single constant value it returns, whereas flattening cursors can return different values during traversal. Another thing to notice that matching START_ELEMENT and END_ELEMENT will always correspond to the same parent count.

      For example, here are expected return values for an example XML document:

        <!-- Comment outside tree --> [0]
        <root> [0]
          Text [1]
          <branch> [1]
            Inner text [2]
            <child /> [2]/[2]
          </branch> [1]
        </root> [0]
      
      Numbers in bracket are depths that would be returned when the cursor points to the node.

      Note: depths are different from what many other xml processing APIs (such as Stax and XmlPull)return.

      Specified by:
      getParentCount in class SMInputCursor
      Returns:
      Number of enclosing nesting levels, ie. number of parent start elements for the node that cursor currently points to (or, in case of initial state, that it will point to if scope has node(s)).
    • getNext

      public SMEvent getNext() throws XMLStreamException
      Description copied from class: SMInputCursor
      Main iterating method. Will try to advance the cursor to the next visible event (visibility defined by the filter cursor is configured with, if any), and return event type. If no such events are available, will return null.

      Note that one side-effect of calling this method is to invalidate the child cursor, if one was active. This is done by iterating over any events child cursor (and its descendants if any) might expose.

      Specified by:
      getNext in class SMInputCursor
      Returns:
      Type of event (from XMLStreamConstants, such as XMLStreamConstants.START_ELEMENT, if a new node was iterated over; null when there are no more nodes this cursor can iterate over.
      Throws:
      XMLStreamException - If there are underlying parsing problems.
    • constructChildCursor

      public SMInputCursor constructChildCursor(SMFilter f)
      Description copied from class: SMInputCursor
      Abstract method that concrete sub-classes implement, and is used for all instantiation of child cursors by this cursor instance.

      Note that custom cursor implementations can be used by overriding this method.

      Specified by:
      constructChildCursor in class SMInputCursor
    • constructDescendantCursor

      public SMInputCursor constructDescendantCursor(SMFilter f)
      Description copied from class: SMInputCursor
      Abstract method that concrete sub-classes implement, and is used for all instantiation of descendant cursors by this cursor instance.

      Note that custom cursor implementations can be used by overriding this method.

      Specified by:
      constructDescendantCursor in class SMInputCursor