Class Cursor
- All Implemented Interfaces:
XmlCursor
,XmlTokenSource
public final class Cursor extends Object implements XmlCursor
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.xmlbeans.XmlCursor
XmlCursor.ChangeStamp, XmlCursor.TokenType, XmlCursor.XmlBookmark, XmlCursor.XmlMark
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description boolean
___toNextSibling()
void
_addToSelection()
void
_beginElement(String localName)
void
_beginElement(String localName, String uri)
void
_beginElement(QName name)
void
_clearBookmark(Object key)
void
_clearSelections()
int
_comparePosition(Cursor other)
int
_copyChars(int cch, Cursor to)
boolean
_copyXml(Cursor to)
boolean
_copyXmlContents(Cursor to)
XmlCursor.TokenType
_currentTokenType()
void
_dispose()
XmlDocumentProperties
_documentProperties()
void
_dump()
XmlCursor
_execQuery(String query)
XmlCursor
_execQuery(String query, XmlOptions options)
void
_getAllBookmarkRefs(Collection listToFill)
void
_getAllNamespaces(Map<String,String> addToThis)
String
_getAttributeText(QName attrName)
XmlCursor.XmlBookmark
_getBookmark(Object key)
String
_getChars()
int
_getChars(char[] buf, int off, int cch)
XmlCursor.ChangeStamp
_getDocChangeStamp()
Node
_getDomNode()
QName
_getName()
XmlObject
_getObject()
int
_getSelectionCount()
String
_getTextValue()
int
_getTextValue(char[] chars, int offset, int max)
boolean
_hasNextSelection()
boolean
_hasNextToken()
boolean
_hasPrevToken()
void
_insertAttribute(String localName)
void
_insertAttribute(String localName, String uri)
void
_insertAttribute(QName name)
void
_insertAttributeWithValue(String localName, String value)
void
_insertAttributeWithValue(String localName, String uri, String value)
void
_insertAttributeWithValue(QName name, String text)
void
_insertChars(String text)
void
_insertComment(String text)
void
_insertElement(String localName)
void
_insertElement(String localName, String uri)
void
_insertElement(QName name)
void
_insertElementWithText(String localName, String text)
void
_insertElementWithText(String localName, String uri, String text)
void
_insertElementWithText(QName name, String text)
void
_insertNamespace(String prefix, String namespace)
void
_insertProcInst(String target, String text)
boolean
_isAnyAttr()
boolean
_isAtSamePositionAs(Cursor other)
boolean
_isAttr()
boolean
_isComment()
boolean
_isContainer()
boolean
_isEnd()
boolean
_isEnddoc()
boolean
_isFinish()
boolean
_isLeftOf(Cursor other)
boolean
_isNamespace()
boolean
_isProcinst()
boolean
_isRightOf(Cursor other)
boolean
_isStart()
boolean
_isStartdoc()
boolean
_isText()
Object
_monitor()
int
_moveChars(int cch, Cursor to)
boolean
_moveXml(Cursor to)
boolean
_moveXmlContents(Cursor to)
String
_namespaceForPrefix(String prefix)
XmlCursor
_newCursor()
Node
_newDomNode()
Node
_newDomNode(XmlOptions options)
InputStream
_newInputStream()
InputStream
_newInputStream(XmlOptions options)
Reader
_newReader()
Reader
_newReader(XmlOptions options)
XMLStreamReader
_newXMLStreamReader()
XMLStreamReader
_newXMLStreamReader(XmlOptions options)
boolean
_pop()
String
_prefixForNamespace(String ns)
XmlCursor.TokenType
_prevTokenType()
void
_push()
boolean
_removeAttribute(QName attrName)
int
_removeChars(int cch)
boolean
_removeXml()
boolean
_removeXmlContents()
void
_save(File file)
void
_save(File file, XmlOptions options)
void
_save(OutputStream os)
void
_save(OutputStream os, XmlOptions options)
void
_save(Writer w)
void
_save(Writer w, XmlOptions options)
void
_save(ContentHandler ch, LexicalHandler lh)
void
_save(ContentHandler ch, LexicalHandler lh, XmlOptions options)
void
_selectPath(String path)
void
_selectPath(String pathExpr, XmlOptions options)
boolean
_setAttributeText(QName attrName, String value)
void
_setBookmark(XmlCursor.XmlBookmark bookmark)
void
_setName(QName name)
void
_setTextValue(char[] sourceChars, int offset, int length)
void
_setTextValue(String text)
boolean
_toBookmark(XmlCursor.XmlBookmark bookmark)
boolean
_toChild(int index)
boolean
_toChild(String local)
boolean
_toChild(String uri, String local)
boolean
_toChild(QName name)
boolean
_toChild(QName name, int index)
boolean
_toCursor(Cursor other)
void
_toEndDoc()
XmlCursor.TokenType
_toEndToken()
boolean
_toFirstAttribute()
boolean
_toFirstChild()
XmlCursor.TokenType
_toFirstContentToken()
boolean
_toLastAttribute()
boolean
_toLastChild()
boolean
_toNextAttribute()
XmlCursor.XmlBookmark
_toNextBookmark(Object key)
int
_toNextChar(int maxCharacterCount)
boolean
_toNextSelection()
boolean
_toNextSibling(String name)
boolean
_toNextSibling(String uri, String local)
boolean
_toNextSibling(QName name)
XmlCursor.TokenType
_toNextToken()
boolean
_toParent()
boolean
_toPrevAttribute()
XmlCursor.XmlBookmark
_toPrevBookmark(Object key)
int
_toPrevChar(int maxCharacterCount)
boolean
_toPrevSibling()
XmlCursor.TokenType
_toPrevToken()
boolean
_toSelection(int i)
void
_toStartDoc()
String
_xmlText()
String
_xmlText(XmlOptions options)
void
addToSelection()
Appends the current location of the cursor to the selection.void
beginElement(String localName)
Inserts a new element around this cursor, giving the element the specified local name.void
beginElement(String localName, String uri)
Inserts a new element around this cursor, giving the element the specified local name and associating it with the specified namespace.void
beginElement(QName name)
Inserts a new element around this cursor, giving the element the specified qualified name.void
clearBookmark(Object key)
Clears the bookmark whose key is specified, if the bookmark exists at this cursor's location.void
clearSelections()
Clears this cursor's selection, but does not modify the document.int
comparePosition(XmlCursor xOther)
Returns an integer indicating whether this cursor is before, after, or at the same position as the specified cursor.int
copyChars(int cch, XmlCursor xTo)
Copies characters to the position immediately after the specified cursor.boolean
copyXml(XmlCursor xTo)
Copies the XML immediately after this cursor to the location specified by the toHere cursor.boolean
copyXmlContents(XmlCursor xTo)
Copies the contents of the container (STARTDOC OR START) immediately to the right of the cursor to the location specified by the toHere cursor.XmlCursor.TokenType
currentTokenType()
Returns the type of the current token.void
dispose()
Deallocates resources needed to manage the cursor, rendering this cursor inoperable.XmlDocumentProperties
documentProperties()
Returns the XmlDocumentProperties object for the document this token source is associated with.void
dump()
Prints to stdout the state of the document in which this token source is positioned.void
dump(PrintStream o)
XmlCursor
execQuery(String query)
Executes the specified XQuery expression against the XML this cursor is in.XmlCursor
execQuery(String query, XmlOptions options)
Executes the specified XQuery expression against the XML this cursor is in, and using the specified options.void
getAllBookmarkRefs(Collection listToFill)
Retrieves all the bookmarks at this location, adding them to the specified collection.void
getAllNamespaces(Map<String,String> addToThis)
Adds to the specified map, all the namespaces in scope at the container where this cursor is positioned.String
getAttributeText(QName attrName)
When at a START or STARTDOC, returns the attribute text for the given attribute.XmlCursor.XmlBookmark
getBookmark(Object key)
Retrieves the bookmark with the specified key at this cursor's location.String
getChars()
Returns characters to the right of the cursor up to the next token.int
getChars(char[] chars, int offset, int cch)
Copies characters up to the specified maximum number, counting right from this cursor's location to the character at maxCharacterCount.XmlCursor.ChangeStamp
getDocChangeStamp()
Returns the current change stamp for the document the current cursor is in.Node
getDomNode()
Returns a W3C DOM Node containing the XML represented by this source.QName
getName()
Returns the name of the current token.org.apache.xmlbeans.impl.store.Locale.ChangeListener
getNextChangeListener()
XmlObject
getObject()
Returns the strongly-typed XmlObject at the current START, STARTDOC, or ATTR.int
getSelectionCount()
Returns the count of the current selection.String
getTextValue()
Gets the text value of the current document, element, attribute, comment, procinst or text token.int
getTextValue(char[] chars, int offset, int cch)
Copies the text value of the current document, element, attribute, comment, processing instruction or text token, counting right from this cursor's location up to maxCharacterCount, and copies the returned text into returnedChars.boolean
hasNextSelection()
Returns whether or not there is a next selection.boolean
hasNextToken()
True if there is a next token.boolean
hasPrevToken()
True if there is a previous token.void
insertAttribute(String localName)
Inserts a new attribute immediately before this cursor's location, giving it the specified local name.void
insertAttribute(String localName, String uri)
Inserts a new attribute immediately before this cursor's location, giving it the specified local name and associating it with the specified namespace.void
insertAttribute(QName name)
Inserts a new attribute immediately before this cursor's location, giving it the specified name.void
insertAttributeWithValue(String name, String value)
Inserts a new attribute immediately before this cursor's location, giving it the specified value and name.void
insertAttributeWithValue(String name, String uri, String value)
Inserts an attribute immediately before the cursor's location, giving it the specified name and value, and associating it with the specified namespace.void
insertAttributeWithValue(QName name, String value)
Inserts an attribute immediately before the cursor's location, giving it the specified name and value.void
insertChars(String text)
Inserts the specified text immediately before this cursor's location.void
insertComment(String text)
Inserts an XML comment immediately before the cursor's location, giving it the specified content.void
insertElement(String localName)
Inserts an element immediately before this cursor's location, giving the element the specified local name.void
insertElement(String localName, String uri)
Inserts a new element immediately before this cursor's location, giving the element the specified local name and associating it with specified namespacevoid
insertElement(QName name)
Inserts an element immediately before this cursor's location, giving the element the specified qualified name.void
insertElementWithText(String localName, String text)
Inserts a new element immediately before this cursor's location, giving the element the specified local name and content.void
insertElementWithText(String localName, String uri, String text)
Inserts a new element immediately before this cursor's location, giving the element the specified local name, associating it with the specified namespace, and giving it the specified content.void
insertElementWithText(QName name, String text)
Inserts a new element immediately before this cursor's location, giving the element the specified qualified name and content.void
insertNamespace(String prefix, String namespace)
Inserts a namespace declaration immediately before the cursor's location, giving it the specified prefix and URI.void
insertProcInst(String target, String text)
Inserts an XML processing instruction immediately before the cursor's location, giving it the specified target and text.boolean
isAnyAttr()
True if this token is any attribute.boolean
isAtSamePositionAs(XmlCursor xOther)
Determines if this cursor is at the same position as the specified cursor.boolean
isAttr()
True if this token is an ATTR token type, meaning just before an attribute.boolean
isComment()
True if this token is a COMMENT token type, meaning just before a comment.boolean
isContainer()
True if this token is a container token.boolean
isEnd()
True if this token is an END token type, meaning just before an element's end.boolean
isEnddoc()
True if this token is an ENDDOC token type, meaning at the very end of the document.boolean
isFinish()
True if this token is a finish token.boolean
isInSameDocument(XmlCursor xOther)
Determines if the specified cursor is in the same document as this cursor.boolean
isLeftOf(XmlCursor xOther)
Determines if this cursor is to the left of (or before) the specified cursor.boolean
isNamespace()
True if this token is a NAMESPACE token type, meaning just before a namespace declaration.boolean
isProcinst()
True if this token is a PROCINST token type, meaning just before a processing instruction.boolean
isRightOf(XmlCursor xOther)
Determines if this cursor is to the right of (or after) the specified cursor.boolean
isStart()
True if this token is a START token type, meaning just before an element's start.boolean
isStartdoc()
True if the current token is a STARTDOC token type, meaning at the very root of the document.boolean
isText()
True if the this token is a TEXT token type, meaning just before or inside text.Object
monitor()
Returns the synchronization object for the document.int
moveChars(int cch, XmlCursor xTo)
Moves characters immediately after this cursor to the position immediately after the specified cursor.boolean
moveXml(XmlCursor xTo)
Moves the XML immediately after this cursor to the location specified by the toHere cursor, shifting XML at that location to the right to make room.boolean
moveXmlContents(XmlCursor xTo)
Moves the contents of the container (STARTDOC OR START) immediately after this cursor to the location specified by the toHere cursor.String
namespaceForPrefix(String prefix)
Returns the namespace URI indicated by the given prefix.XmlCursor
newCursor()
Returns a new XML cursor.static XmlCursor
newCursor(org.apache.xmlbeans.impl.store.Xobj x, int p)
Node
newDomNode()
Returns a W3C DOM Node containing the XML represented by this source.Node
newDomNode(XmlOptions options)
Just like newDomNode() but with options.InputStream
newInputStream()
Returns a new stream containing standard XML text, encoded according to the given encoding.InputStream
newInputStream(XmlOptions options)
Just like newInputStream(String encoding) but with options.Reader
newReader()
Returns a new character reader containing XML text.Reader
newReader(XmlOptions options)
Just like newReader() but with options.XMLStreamReader
newXMLStreamReader()
Returns a new XMLStreamReader.XMLStreamReader
newXMLStreamReader(XmlOptions options)
Returns a new XMLStreamReader.void
notifyChange()
boolean
pop()
Restores the cursor location most recently saved with the push() method.String
prefixForNamespace(String namespaceURI)
Returns a prefix that can be used to indicate a namespace URI.XmlCursor.TokenType
prevTokenType()
Returns the type of the previous token.void
push()
Saves the current location of this cursor on an internal stack of saved positions (independent of selection).boolean
removeAttribute(QName attrName)
When at a START or STARTDOC, removes the attribute with the given name.int
removeChars(int cch)
Removes characters up to the specified maximum number, counting right from this cursor's location to the character at maxCharacterCount.boolean
removeXml()
Removes the XML that is immediately after this cursor.boolean
removeXmlContents()
Removes the contents of the container (STARTDOC OR START) immediately after this cursor.void
save(File file)
Writes the XML represented by this source to the given File.void
save(File file, XmlOptions options)
Writes the XML represented by this source to the given File.void
save(OutputStream os)
Writes the XML represented by this source to the given output stream.void
save(OutputStream os, XmlOptions options)
Writes the XML represented by this source to the given output stream.void
save(Writer w)
Writes the XML represented by this source to the given output.void
save(Writer w, XmlOptions options)
Writes the XML represented by this source to the given output.void
save(ContentHandler ch, LexicalHandler lh)
Writes the XML represented by this source to the given SAX content and lexical handlers.void
save(ContentHandler ch, LexicalHandler lh, XmlOptions options)
Writes the XML represented by this source to the given SAX content and lexical handlers.void
selectPath(String path)
Executes the specified XPath expression against the XML that this cursor is in.void
selectPath(String path, XmlOptions options)
Executes the specified XPath expression against the XML that this cursor is in.boolean
setAttributeText(QName attrName, String value)
When at a START or STARTDOC, sets the attribute text for the given attribute.void
setBookmark(XmlCursor.XmlBookmark bookmark)
Sets a bookmark to the document at this cursor's location.void
setName(QName name)
Sets the name of the current token.void
setNextChangeListener(org.apache.xmlbeans.impl.store.Locale.ChangeListener listener)
void
setTextValue(char[] sourceChars, int offset, int length)
Sets the text value of the XML at this cursor's location (if that XML's token type is START, STARTDOC, ATTR, COMMENT or PROCINST) to the contents of the specified character array.void
setTextValue(String text)
Sets the text value of the XML at this cursor's location if that XML's token type is START, STARTDOC, ATTR, COMMENT or PROCINST.boolean
toBookmark(XmlCursor.XmlBookmark bookmark)
Moves this cursor to the same position as the bookmark.boolean
toChild(int index)
Moves the cursor to the child element specified by index.boolean
toChild(String name)
Moves the cursor to the first child element of the specified name in no namespace.boolean
toChild(String namespace, String name)
Moves the cursor to the first child element of the specified name in the specified namespace.boolean
toChild(QName name)
Moves the cursor to the first child element of the specified qualified name.boolean
toChild(QName name, int index)
Moves the cursor to the specified index child element of the specified name, where that element is the .boolean
toCursor(XmlCursor xOther)
Moves this cursor to the same position as the moveTo cursor.void
toEndDoc()
Moves the cursor to the ENDDOC token, which is the end of the document.XmlCursor.TokenType
toEndToken()
Moves the cursor to the END or ENDDOC token corresponding to the current START or STARTDOC, and returns END or ENDDOC.boolean
toFirstAttribute()
Moves the cursor to the first attribute of this element, or returns false and does not move the cursor if there are no attributes.boolean
toFirstChild()
Moves the cursor to the first child element, or returns false and does not move the cursor if there are no element children.XmlCursor.TokenType
toFirstContentToken()
Moves the cursor to the first token in the content of the current START or STARTDOC.boolean
toLastAttribute()
Moves the cursor to the last attribute of this element, or returns false and does not move the cursor if there are no attributes.boolean
toLastChild()
Moves the cursor to the last element child, or returns false and does not move the cursor if there are no element children.boolean
toNextAttribute()
Moves the cursor to the next sibling attribute, or returns false and does not move the cursor if there is no next sibling attribute.XmlCursor.XmlBookmark
toNextBookmark(Object key)
Moves this cursor to the location after its current position where a bookmark with the given key exists.int
toNextChar(int cch)
Moves the cursor forward by the specified number of characters, and stops at the next non-TEXT token.boolean
toNextSelection()
Moves this cursor to the next location in the selection, if any.boolean
toNextSibling()
Moves the cursor to the next sibling element, or returns false and does not move the cursor if there is no next sibling element.boolean
toNextSibling(String name)
Moves the cursor to the next sibling element of the specified name in no namespace.boolean
toNextSibling(String namespace, String name)
Moves the cursor to the next sibling element of the specified name in the specified namespace.boolean
toNextSibling(QName name)
Moves the cursor to the next sibling element of the specified qualified name.XmlCursor.TokenType
toNextToken()
Moves the cursor to the next token.boolean
toParent()
Moves the cursor to the parent element or STARTDOC, or returns false and does not move the cursor if there is no parent.boolean
toPrevAttribute()
Moves the cursor to the previous sibling attribute, or returns false and does not move the cursor if there is no previous sibling attribute.XmlCursor.XmlBookmark
toPrevBookmark(Object key)
Moves this cursor to the location before its current position where a bookmark with the given key exists.int
toPrevChar(int cch)
Moves the cursor backwards by the number of characters given.boolean
toPrevSibling()
Moves the cursor to the previous sibling element, or returns false and does not move the cursor if there is no previous sibling element.XmlCursor.TokenType
toPrevToken()
Moves the cursor to the previous token.boolean
toSelection(int i)
Moves this cursor to the specified location in the selection.void
toStartDoc()
Moves the cursor to the STARTDOC token, which is the root of the document.String
xmlText()
Returns standard XML text.String
xmlText(XmlOptions options)
Just like xmlText() but with options.
-
Constructor Details
-
Method Details
-
dump
-
_dispose
public void _dispose() -
_newCursor
-
_getName
-
_setName
-
_currentTokenType
-
_isStartdoc
public boolean _isStartdoc() -
_isEnddoc
public boolean _isEnddoc() -
_isStart
public boolean _isStart() -
_isEnd
public boolean _isEnd() -
_isText
public boolean _isText() -
_isAttr
public boolean _isAttr() -
_isNamespace
public boolean _isNamespace() -
_isComment
public boolean _isComment() -
_isProcinst
public boolean _isProcinst() -
_isContainer
public boolean _isContainer() -
_isFinish
public boolean _isFinish() -
_isAnyAttr
public boolean _isAnyAttr() -
_toNextToken
-
_toPrevToken
-
_monitor
-
_toParent
public boolean _toParent() -
_getDocChangeStamp
-
_newXMLStreamReader
-
_newDomNode
-
_newInputStream
-
_xmlText
-
_newReader
-
_save
- Throws:
IOException
-
_save
- Throws:
IOException
-
_save
- Throws:
IOException
-
_save
- Throws:
SAXException
-
_documentProperties
-
_newXMLStreamReader
-
_xmlText
-
_newInputStream
-
_newReader
-
_save
- Throws:
SAXException
-
_save
- Throws:
IOException
-
_save
- Throws:
IOException
-
_save
- Throws:
IOException
-
_getDomNode
-
_newDomNode
-
_toCursor
-
_push
public void _push() -
_pop
public boolean _pop() -
notifyChange
public void notifyChange() -
setNextChangeListener
public void setNextChangeListener(org.apache.xmlbeans.impl.store.Locale.ChangeListener listener) -
getNextChangeListener
public org.apache.xmlbeans.impl.store.Locale.ChangeListener getNextChangeListener() -
_selectPath
-
_selectPath
-
_hasNextSelection
public boolean _hasNextSelection() -
_toNextSelection
public boolean _toNextSelection() -
_toSelection
public boolean _toSelection(int i) -
_getSelectionCount
public int _getSelectionCount() -
_addToSelection
public void _addToSelection() -
_clearSelections
public void _clearSelections() -
_namespaceForPrefix
-
_prefixForNamespace
-
_getAllNamespaces
-
_getObject
-
_prevTokenType
-
_hasNextToken
public boolean _hasNextToken() -
_hasPrevToken
public boolean _hasPrevToken() -
_toFirstContentToken
-
_toEndToken
-
_toChild
-
_toChild
-
_toChild
public boolean _toChild(int index) -
_toChild
-
_toChild
-
_toNextChar
public int _toNextChar(int maxCharacterCount) -
_toPrevChar
public int _toPrevChar(int maxCharacterCount) -
_toPrevSibling
public boolean _toPrevSibling() -
_toLastChild
public boolean _toLastChild() -
_toFirstChild
public boolean _toFirstChild() -
_toNextSibling
-
_toNextSibling
-
_toNextSibling
-
_toFirstAttribute
public boolean _toFirstAttribute() -
_toLastAttribute
public boolean _toLastAttribute() -
_toNextAttribute
public boolean _toNextAttribute() -
_toPrevAttribute
public boolean _toPrevAttribute() -
_getAttributeText
-
_setAttributeText
-
_removeAttribute
-
_getTextValue
-
_getTextValue
public int _getTextValue(char[] chars, int offset, int max) -
_setTextValue
-
_setTextValue
public void _setTextValue(char[] sourceChars, int offset, int length) -
_getChars
-
_getChars
public int _getChars(char[] buf, int off, int cch) -
_toStartDoc
public void _toStartDoc() -
_toEndDoc
public void _toEndDoc() -
_comparePosition
-
_isLeftOf
-
_isAtSamePositionAs
-
_isRightOf
-
_execQuery
-
_execQuery
-
_toBookmark
-
_toNextBookmark
-
_toPrevBookmark
-
_setBookmark
-
_getBookmark
-
_clearBookmark
-
_getAllBookmarkRefs
-
_removeXml
public boolean _removeXml() -
_moveXml
-
_copyXml
-
_removeXmlContents
public boolean _removeXmlContents() -
_moveXmlContents
-
_copyXmlContents
-
_removeChars
public int _removeChars(int cch) -
_moveChars
-
_copyChars
-
_insertChars
-
_beginElement
-
_beginElement
-
_beginElement
-
_insertElement
-
_insertElement
-
_insertElement
-
_insertElementWithText
-
_insertElementWithText
-
_insertElementWithText
-
_insertAttribute
-
_insertAttribute
-
_insertAttribute
-
_insertAttributeWithValue
-
_insertAttributeWithValue
-
_insertAttributeWithValue
-
_insertNamespace
-
_insertComment
-
_insertProcInst
-
_dump
public void _dump() -
moveXml
Description copied from interface:XmlCursor
Moves the XML immediately after this cursor to the location specified by the toHere cursor, shifting XML at that location to the right to make room. For the TEXT, ATTR, NAMESPACE, COMMENT and PROCINST tokens, a single token is moved. For a start token, the element and all of its contents are moved. For all other tokens, this is a no-op.The bookmarks located in the XML that was moved also move to the new location; the cursors don't move with the content.
-
copyXml
Description copied from interface:XmlCursor
Copies the XML immediately after this cursor to the location specified by the toHere cursor. For the TEXT, ATTR, NAMESPACE, COMMENT and PROCINST tokens, a single token is copied. For a start token, the element and all of its contents are copied. For all other tokens, this is a no-op.The cursors and bookmarks located in the XML that was copied are also copied to the new location.
-
moveXmlContents
Description copied from interface:XmlCursor
Moves the contents of the container (STARTDOC OR START) immediately after this cursor to the location specified by the toHere cursor. For all other situations, returns false. Does not move attributes or namespaces.- Specified by:
moveXmlContents
in interfaceXmlCursor
- Parameters:
xTo
- The cursor at the location to which the XML should be moved.- Returns:
- true if anything was moved; otherwise, false.
-
copyXmlContents
Description copied from interface:XmlCursor
Copies the contents of the container (STARTDOC OR START) immediately to the right of the cursor to the location specified by the toHere cursor. For all other situations, returns false. Does not copy attributes or namespaces.- Specified by:
copyXmlContents
in interfaceXmlCursor
- Parameters:
xTo
- The cursor at the location to which the XML should be copied.- Returns:
- true if anything was copied; otherwise, false.
-
moveChars
Description copied from interface:XmlCursor
Moves characters immediately after this cursor to the position immediately after the specified cursor. Characters are counted to the right up to the specified maximum number. XML after the destination cursor is shifted to the right to make room. The space remaining from moving the characters collapses up to this cursor. -
copyChars
Description copied from interface:XmlCursor
Copies characters to the position immediately after the specified cursor. Characters are counted to the right up to the specified maximum number. XML after the destination cursor is shifted to the right to make room. -
toCursor
Description copied from interface:XmlCursor
Moves this cursor to the same position as the moveTo cursor. if the moveTo cursor is in a different document from this cursor, this cursor will not be moved, and false returned. -
isInSameDocument
Description copied from interface:XmlCursor
Determines if the specified cursor is in the same document as this cursor.- Specified by:
isInSameDocument
in interfaceXmlCursor
- Parameters:
xOther
- The cursor that may be in the same document as this cursor.- Returns:
- true if the specified cursor is in the same document; otherwise, false.
-
comparePosition
Description copied from interface:XmlCursor
Returns an integer indicating whether this cursor is before, after, or at the same position as the specified cursor.
a.comparePosition(b) < 0
means a is to the left of b.
a.comparePosition(b) == 0
means a is at the same position as b.
a.comparePosition(b) > 0
means a is to the right of b.
The sort order of cursors in the document is the token order. For example, if cursor "a" is at a START token and the cursor "b" is at a token within the contents of the same element, then a.comparePosition(b) will return -1, meaning that the position of a is before b.
- Specified by:
comparePosition
in interfaceXmlCursor
- Parameters:
xOther
- The cursor whose position should be compared with this cursor.- Returns:
- 1 if this cursor is after the specified cursor; 0 if this cursor is at the same position as the specified cursor; -1 if this cursor is before the specified cursor.
-
isLeftOf
Description copied from interface:XmlCursor
Determines if this cursor is to the left of (or before) the specified cursor. Note that this is the same asa.comparePosition(b) < 0
-
isAtSamePositionAs
Description copied from interface:XmlCursor
Determines if this cursor is at the same position as the specified cursor. Note that this is the same asa.comparePosition(b) == 0
- Specified by:
isAtSamePositionAs
in interfaceXmlCursor
- Parameters:
xOther
- The cursor whose position should be compared with this cursor.- Returns:
- true if this cursor is at the same position as the specified cursor; otherwise, false.
-
isRightOf
Description copied from interface:XmlCursor
Determines if this cursor is to the right of (or after) the specified cursor. Note that this is the same asa.comparePosition(b) > 0
-
newCursor
-
dispose
public void dispose()Description copied from interface:XmlCursor
Deallocates resources needed to manage the cursor, rendering this cursor inoperable. Because cursors are managed by a mechanism which stores the XML, simply letting a cursor go out of scope and having the garbage collector attempt to reclaim it may not produce desirable performance.
So, explicitly disposing a cursor allows the underlying implementation to release its responsibility of maintaining its position.
After a cursor has been disposed, it may not be used again. It can throw IllegalStateException or NullPointerException if used after disposal.
-
monitor
Description copied from interface:XmlTokenSource
Returns the synchronization object for the document. If concurrent multithreaded access to a document is required, the access should should be protected by synchronizing on this monitor() object. There is one monitor per XML document tree.- Specified by:
monitor
in interfaceXmlTokenSource
-
documentProperties
Description copied from interface:XmlTokenSource
Returns the XmlDocumentProperties object for the document this token source is associated with.- Specified by:
documentProperties
in interfaceXmlTokenSource
-
newCursor
Description copied from interface:XmlTokenSource
Returns a new XML cursor.A cursor provides random access to all the tokens in the XML data, plus the ability to extract strongly-typed XmlObjects for the data. If the data is not read-only, the XML cursor also allows modifications to the data.
Using a cursor for the first time typically forces the XML document into memory.
- Specified by:
newCursor
in interfaceXmlTokenSource
-
newXMLStreamReader
Description copied from interface:XmlTokenSource
Returns a new XMLStreamReader.The stream starts at the current begin-tag or begin-document position and ends at the matching end-tag or end-document.
This is a fail-fast stream, so if the underlying data is changed while the stream is being read, the stream throws a ConcurrentModificationException.
- Specified by:
newXMLStreamReader
in interfaceXmlTokenSource
-
newXMLStreamReader
Description copied from interface:XmlTokenSource
Returns a new XMLStreamReader.The stream starts at the current begin-tag or begin-document position and ends at the matching end-tag or end-document.
This is a fail-fast stream, so if the underlying data is changed while the stream is being read, the stream throws a ConcurrentModificationException.
Throws an IllegalStateException if the XmlTokenSource is not positioned at begin-tag or begin-document (e.g., if it is at an attribute).
To specify this Use this method The character encoding to use when converting the character data in the XML to bytess. XmlOptions.setCharacterEncoding(java.lang.String)
Prefix-to-namespace mappings that should be assumed when saving this XML. This is useful when the resulting XML will be part of a larger XML document, ensuring that this inner document will take advantage of namespaces defined in the outer document. XmlOptions.setSaveImplicitNamespaces(java.util.Map<java.lang.String, java.lang.String>)
Suggested namespace prefixes to use when saving. Used only when a namespace attribute needs to be synthesized. XmlOptions.setSaveSuggestedPrefixes(java.util.Map<java.lang.String, java.lang.String>)
That namespace attributes should occur first in elements when the XML is saved. By default, they occur last. XmlOptions.setSaveNamespacesFirst()
The XML should be pretty printed when saved. Note that this should only be used for debugging. XmlOptions.setSavePrettyPrint()
The number of spaces to use when indenting for pretty printing. The default is 2. XmlOptions.setSavePrettyPrintIndent(int)
The additional number of spaces indented from the left for pretty printed XML. XmlOptions.setSavePrettyPrintOffset(int)
To minimize the number of namespace attributes generated for the saved XML. Note that this can reduce performance significantly. XmlOptions.setSaveAggressiveNamespaces()
To reduce the size of the saved document by allowing the use of the default namespace. Note that this can potentially change the semantic meaning of the XML if unprefixed QNames are present as the value of an attribute or element. XmlOptions.setUseDefaultNamespace()
To filter out processing instructions with the specified target name. XmlOptions.setSaveFilterProcinst(java.lang.String)
Change the QName of the synthesized root element when saving. This replaces "xml-fragment" with "fragment" in the namespace http://www.openuri.org/fragment XmlOptions.setSaveUseOpenFrag()
Saving should begin on the element's contents. XmlOptions.setSaveInner()
Saving should begin on the element, rather than its contents. XmlOptions.setSaveOuter()
To rename the document element, or to specify the document element for this XML. XmlOptions.setSaveSyntheticDocumentElement(javax.xml.namespace.QName)
- Specified by:
newXMLStreamReader
in interfaceXmlTokenSource
- Parameters:
options
- Any of the described options. Options map may be null.- Returns:
- A new validating XMLStreamReader.
- See Also:
XmlOptions
-
xmlText
Description copied from interface:XmlTokenSource
Returns standard XML text.The text returned represents the document contents starting at the current begin-tag or begin-document and ending at the matching end-tag or end-document. This is same content as newReader, but it is returned as a single string.
Throws an IllegalStateException if the XmlTokenSource is not positioned at begin-tag or begin-document (e.g., if it is at an attribute).
Note that this method does not produce XML with the XML declaration, including the encoding information. To save the XML declaration with the XML, see
XmlTokenSource.save(OutputStream)
orXmlTokenSource.save(OutputStream, XmlOptions)
.- Specified by:
xmlText
in interfaceXmlTokenSource
-
newInputStream
Description copied from interface:XmlTokenSource
Returns a new stream containing standard XML text, encoded according to the given encoding.The byte stream contains contents starting at the current begin-tag or begin-document and ending at the matching end-tag or end-document. The specified encoding is used and also emitted in a PI at the beginning of the stream.
This is a fail-fast stream, so if the underlying data is changed while the stream is being read, the stream throws a ConcurrentModificationException.
Throws an IllegalStateException if the XmlTokenSource is not positioned at begin-tag or begin-document (e.g., if it is at an attribute).
- Specified by:
newInputStream
in interfaceXmlTokenSource
-
newReader
Description copied from interface:XmlTokenSource
Returns a new character reader containing XML text.The contents of the reader represents the document contents starting at the current begin-tag or begin-document and ending at the matching end-tag or end-document. No encoding annotation will be made in the text itself.
This is a fail-fast reader, so if the underlying data is changed while the reader is being read, the reader throws a ConcurrentModificationException.
Throws an IllegalStateException if the XmlTokenSource is not positioned at begin-tag or begin-document (e.g., if it is at an attribute).
- Specified by:
newReader
in interfaceXmlTokenSource
-
newDomNode
Description copied from interface:XmlTokenSource
Returns a W3C DOM Node containing the XML represented by this source. This is a copy of the XML, it is not a live with the underlying store of this token source. If this is the document node, then a Document is returned, else a DocumentFragment is returned.- Specified by:
newDomNode
in interfaceXmlTokenSource
-
getDomNode
Description copied from interface:XmlTokenSource
Returns a W3C DOM Node containing the XML represented by this source. This is a live DOM node, not a copy. Any changes made through this node are immediately reflected in the document associated with this token source. Depending on the kind of token this XmlTokenSource represents, an appropriate node will be returned.- Specified by:
getDomNode
in interfaceXmlTokenSource
-
save
Description copied from interface:XmlTokenSource
Writes the XML represented by this source to the given SAX content and lexical handlers. Note that this method does not save the XML declaration, including the encoding information. To save the XML declaration with the XML, seeXmlTokenSource.save(OutputStream)
,XmlTokenSource.save(OutputStream, XmlOptions)
,XmlTokenSource.save(File)
orXmlTokenSource.save(File, XmlOptions)
.- Specified by:
save
in interfaceXmlTokenSource
- Throws:
SAXException
-
save
Description copied from interface:XmlTokenSource
Writes the XML represented by this source to the given File. This method will save the XML declaration, including encoding information, with the XML.- Specified by:
save
in interfaceXmlTokenSource
- Throws:
IOException
-
save
Description copied from interface:XmlTokenSource
Writes the XML represented by this source to the given output stream. This method will save the XML declaration, including encoding information, with the XML.- Specified by:
save
in interfaceXmlTokenSource
- Throws:
IOException
-
save
Description copied from interface:XmlTokenSource
Writes the XML represented by this source to the given output. Note that this method does not save the XML declaration, including the encoding information. To save the XML declaration with the XML, seeXmlTokenSource.save(OutputStream)
,XmlTokenSource.save(OutputStream, XmlOptions)
,XmlTokenSource.save(File)
orXmlTokenSource.save(File, XmlOptions)
.- Specified by:
save
in interfaceXmlTokenSource
- Throws:
IOException
-
xmlText
Description copied from interface:XmlTokenSource
Just like xmlText() but with options. Options map may be null.Note that this method does not produce XML with the XML declaration, including the encoding information. To save the XML declaration with the XML, see
XmlTokenSource.save(OutputStream)
orXmlTokenSource.save(OutputStream, XmlOptions)
.- Specified by:
xmlText
in interfaceXmlTokenSource
- See Also:
XmlOptions
-
newInputStream
Description copied from interface:XmlTokenSource
Just like newInputStream(String encoding) but with options. Options map may be null.- Specified by:
newInputStream
in interfaceXmlTokenSource
- See Also:
XmlOptions
-
newReader
Description copied from interface:XmlTokenSource
Just like newReader() but with options. Options map may be null.- Specified by:
newReader
in interfaceXmlTokenSource
- See Also:
XmlOptions
-
newDomNode
Description copied from interface:XmlTokenSource
Just like newDomNode() but with options. Options map may be null.- Specified by:
newDomNode
in interfaceXmlTokenSource
- See Also:
XmlOptions
-
save
Description copied from interface:XmlTokenSource
Writes the XML represented by this source to the given SAX content and lexical handlers. Note that this method does not save the XML declaration, including the encoding information. To save the XML declaration with the XML, seeXmlTokenSource.save(OutputStream)
,XmlTokenSource.save(OutputStream, XmlOptions)
,XmlTokenSource.save(File)
orXmlTokenSource.save(File, XmlOptions)
.- Specified by:
save
in interfaceXmlTokenSource
- Throws:
SAXException
-
save
Description copied from interface:XmlTokenSource
Writes the XML represented by this source to the given File. This method will save the XML declaration, including encoding information, with the XML.- Specified by:
save
in interfaceXmlTokenSource
- Throws:
IOException
-
save
Description copied from interface:XmlTokenSource
Writes the XML represented by this source to the given output stream. This method will save the XML declaration, including encoding information, with the XML.- Specified by:
save
in interfaceXmlTokenSource
- Throws:
IOException
-
save
Description copied from interface:XmlTokenSource
Writes the XML represented by this source to the given output. Note that this method does not save the XML declaration, including the encoding information. To save the XML declaration with the XML, seeXmlTokenSource.save(OutputStream)
,XmlTokenSource.save(OutputStream, XmlOptions)
,XmlTokenSource.save(File)
orXmlTokenSource.save(File, XmlOptions)
.- Specified by:
save
in interfaceXmlTokenSource
- Throws:
IOException
-
push
public void push()Description copied from interface:XmlCursor
Saves the current location of this cursor on an internal stack of saved positions (independent of selection). This location may be restored later by calling the pop() method. -
pop
public boolean pop()Description copied from interface:XmlCursor
Restores the cursor location most recently saved with the push() method. -
selectPath
Description copied from interface:XmlCursor
Executes the specified XPath expression against the XML that this cursor is in. The cursor's position does not change. To navigate to the selections, useXmlCursor.hasNextSelection()
andXmlCursor.toNextSelection()
(similar toIterator
).
The root referred to by the expression should be given as a dot. The following is an example path expression:
cursor.selectPath("./purchase-order/line-item");
Note that this method does not support top-level XPath functions.
- Specified by:
selectPath
in interfaceXmlCursor
- Parameters:
path
- The path expression to execute.
-
selectPath
Description copied from interface:XmlCursor
Executes the specified XPath expression against the XML that this cursor is in. The cursor's position does not change. To navigate to the selections, use hasNextSelection and toNextSelection (similar to java.util.Iterator).
The root referred to by the expression should be given as a dot. The following is an example path expression:
cursor.selectPath("./purchase-order/line-item");
Note that this method does not support top-level XPath functions.
- Specified by:
selectPath
in interfaceXmlCursor
- Parameters:
path
- The path expression to execute.options
- Options for the query. For example, you can call theXmlOptions.setXqueryCurrentNodeVar(String)
method to specify a particular name for the query expression variable that indicates the context node.
-
hasNextSelection
public boolean hasNextSelection()Description copied from interface:XmlCursor
Returns whether or not there is a next selection.- Specified by:
hasNextSelection
in interfaceXmlCursor
- Returns:
- true if there is a next selection; otherwise, false.
-
toNextSelection
public boolean toNextSelection()Description copied from interface:XmlCursor
Moves this cursor to the next location in the selection, if any. See theXmlCursor.selectPath(java.lang.String)
andXmlCursor.addToSelection()
methods.- Specified by:
toNextSelection
in interfaceXmlCursor
- Returns:
- true if the cursor moved; otherwise, false.
-
toSelection
public boolean toSelection(int i)Description copied from interface:XmlCursor
Moves this cursor to the specified location in the selection. If i is less than zero or greater than or equal to the selection count, this method returns false.See also the selectPath() and addToSelection() methods.
- Specified by:
toSelection
in interfaceXmlCursor
- Parameters:
i
- The index of the desired location.- Returns:
- true if the cursor was moved; otherwise, false.
-
getSelectionCount
public int getSelectionCount()Description copied from interface:XmlCursor
Returns the count of the current selection. See also the selectPath() and addToSelection() methods.You may experience better performance if you use the iteration model using the toNextSelection method, rather than the indexing model using the getSelectionCount and toSelection methods.
- Specified by:
getSelectionCount
in interfaceXmlCursor
- Returns:
- A number indicating the size of the current selection.
-
addToSelection
public void addToSelection()Description copied from interface:XmlCursor
Appends the current location of the cursor to the selection. See also the selectPath() method. You can use this as an alternative to calling the selectPath method when you want to define your own selection.- Specified by:
addToSelection
in interfaceXmlCursor
-
clearSelections
public void clearSelections()Description copied from interface:XmlCursor
Clears this cursor's selection, but does not modify the document.- Specified by:
clearSelections
in interfaceXmlCursor
-
toBookmark
Description copied from interface:XmlCursor
Moves this cursor to the same position as the bookmark. If the bookmark is in a different document from this cursor or if the bookmark is orphaned, this cursor will not be moved, and false will be returned.- Specified by:
toBookmark
in interfaceXmlCursor
- Parameters:
bookmark
- The bookmark at the location to which this cursor should be moved.- Returns:
- true if the cursor moved; otherwise, false.
-
toNextBookmark
Description copied from interface:XmlCursor
Moves this cursor to the location after its current position where a bookmark with the given key exists. Returns false if no such bookmark exists.- Specified by:
toNextBookmark
in interfaceXmlCursor
- Parameters:
key
- The key held by the next bookmark at the location to which this cursor should be moved.- Returns:
- The next corresponding bookmark, if it exists; null if there is no next bookmark with the specified key.
-
toPrevBookmark
Description copied from interface:XmlCursor
Moves this cursor to the location before its current position where a bookmark with the given key exists. Returns false if no such bookmark exists.- Specified by:
toPrevBookmark
in interfaceXmlCursor
- Parameters:
key
- The key held by the previous bookmark at the location to which this cursor should be moved.- Returns:
- The previous corresponding bookmark, if it exists; null if there is no previous bookmark with the specified key.
-
getName
Description copied from interface:XmlCursor
Returns the name of the current token. Names may be associated with START, ATTR, NAMESPACE or PROCINST. Returns null if there is no name associated with the current token. For START and ATTR, the name returned identifies the name of the element or attribute. For NAMESPACE, the local part of the name is the prefix, while the URI is the namespace defined. For PROCINST, the local part is the target and the uri is "".In the following example,
xmlObject
represents an XML instance whose root element is not preceded by any other XML. This code prints the root element name (here, the local name, or name without URI).XmlCursor cursor = xmlObject.newCursor(); cursor.toFirstContentToken(); String elementName = cursor.getName().getLocalPart(); System.out.println(elementName);
-
setName
Description copied from interface:XmlCursor
Sets the name of the current token. This token can be START, NAMESPACE, ATTR or PROCINST. -
namespaceForPrefix
Description copied from interface:XmlCursor
Returns the namespace URI indicated by the given prefix. The current context must be at a START or STARTDOC. Namespace prefix mappings are queried for the mappings defined at the current container first, then parents are queried. The prefix can be "" or null to indicate a search for the default namespace. To conform with the XML spec, the default namespace will return the no-namespace ("") if it is not mapped.
Note that this queries the current state of the document. When the document is persisted, the saving mechanism may synthesize namespaces (ns1, ns2, and so on) for the purposes of persistence. These namepaces are only present in the serialized form, and are not reflected back into the document being saved.
- Specified by:
namespaceForPrefix
in interfaceXmlCursor
- Parameters:
prefix
- The namespace prefix for the requested namespace.- Returns:
- The URI for corresponding to the specified prefix if it exists; otherwise, null.
-
prefixForNamespace
Description copied from interface:XmlCursor
Returns a prefix that can be used to indicate a namespace URI. The current context must be at a START or STARTDOC. If there is an existing prefix that indicates the URI in the current context, that prefix may be returned. Otherwise, a new prefix for the URI will be defined by adding an xmlns attribute to the current container or a parent container.Note that this queries the current state of the document. When the document is persisted, the saving mechanism may synthesize namespaces (ns1, ns2, and so on) for the purposes of persistence. These namepaces are only present in the serialized form, and are not reflected back into the document being saved.
- Specified by:
prefixForNamespace
in interfaceXmlCursor
- Parameters:
namespaceURI
- The namespace URI corresponding to the requested prefix.- Returns:
- The prefix corresponding to the specified URI if it exists; otherwise, a newly generated prefix.
-
getAllNamespaces
Description copied from interface:XmlCursor
Adds to the specified map, all the namespaces in scope at the container where this cursor is positioned. This method is useful for container tokens only.- Specified by:
getAllNamespaces
in interfaceXmlCursor
- Parameters:
addToThis
- The Map to add the namespaces to.
-
getObject
Description copied from interface:XmlCursor
Returns the strongly-typed XmlObject at the current START, STARTDOC, or ATTR.
The strongly-typed object can be cast to the strongly-typed XBean interface corresponding to the XML Schema Type given by result.getSchemaType().
If a more specific type cannot be determined, an XmlObject whose schema type is anyType will be returned.
-
currentTokenType
Description copied from interface:XmlCursor
Returns the type of the current token. By definition, the current token is the token immediately to the right of the cursor. If you're in the middle of text, before a character, you get TEXT. You can't dive into the text of an ATTR, COMMENT or PROCINST.
As an alternative, it may be more convenient for you to use one of the methods that test for a particular token type. These include the methods isStart(), isStartdoc(), isText(), isAttr(), and so on. Each returns a boolean value indicating whether the token that follows the cursor is the type in question.
- Specified by:
currentTokenType
in interfaceXmlCursor
- Returns:
- The TokenType instance for the token at the cursor's current location.
-
isStartdoc
public boolean isStartdoc()Description copied from interface:XmlCursor
True if the current token is a STARTDOC token type, meaning at the very root of the document.- Specified by:
isStartdoc
in interfaceXmlCursor
- Returns:
- true if this token is a STARTDOC token type; otherwise, false.
-
isEnddoc
public boolean isEnddoc()Description copied from interface:XmlCursor
True if this token is an ENDDOC token type, meaning at the very end of the document. -
isStart
public boolean isStart()Description copied from interface:XmlCursor
True if this token is a START token type, meaning just before an element's start. -
isEnd
public boolean isEnd()Description copied from interface:XmlCursor
True if this token is an END token type, meaning just before an element's end. -
isText
public boolean isText()Description copied from interface:XmlCursor
True if the this token is a TEXT token type, meaning just before or inside text. -
isAttr
public boolean isAttr()Description copied from interface:XmlCursor
True if this token is an ATTR token type, meaning just before an attribute. -
isNamespace
public boolean isNamespace()Description copied from interface:XmlCursor
True if this token is a NAMESPACE token type, meaning just before a namespace declaration.- Specified by:
isNamespace
in interfaceXmlCursor
- Returns:
- true if this token is a NAMESPACE token type; otherwise, false.
-
isComment
public boolean isComment()Description copied from interface:XmlCursor
True if this token is a COMMENT token type, meaning just before a comment. -
isProcinst
public boolean isProcinst()Description copied from interface:XmlCursor
True if this token is a PROCINST token type, meaning just before a processing instruction.- Specified by:
isProcinst
in interfaceXmlCursor
- Returns:
- true if this token is a PROCINST token type; otherwise, false.
-
isContainer
public boolean isContainer()Description copied from interface:XmlCursor
True if this token is a container token. The STARTDOC and START token types are containers. Containers, including documents and elements, have the same content model. In other words, a document and an element may have the same contents. For example, a document may contain attributes or text, without any child elements.- Specified by:
isContainer
in interfaceXmlCursor
- Returns:
- true if this token is a container token; otherwise, false.
-
isFinish
public boolean isFinish()Description copied from interface:XmlCursor
True if this token is a finish token. A finish token can be an ENDDOC or END token type. -
isAnyAttr
public boolean isAnyAttr()Description copied from interface:XmlCursor
True if this token is any attribute. This includes an ATTR token type and the NAMESPACE token type attribute. -
prevTokenType
Description copied from interface:XmlCursor
Returns the type of the previous token. By definition, the previous token is the token immediately to the left of the cursor.
If you're in the middle of text, after a character, you get TEXT.
- Specified by:
prevTokenType
in interfaceXmlCursor
- Returns:
- The TokenType instance for the token immediately before the token at the cursor's current location.
-
hasNextToken
public boolean hasNextToken()Description copied from interface:XmlCursor
True if there is a next token. When this is false, as when the cursor is at the ENDDOC token, the toNextToken() method returns NONE and does not move the cursor.- Specified by:
hasNextToken
in interfaceXmlCursor
- Returns:
- true if there is a next token; otherwise, false.
-
hasPrevToken
public boolean hasPrevToken()Description copied from interface:XmlCursor
True if there is a previous token. When this is false, toPrevToken returns NONE and does not move the cursor.- Specified by:
hasPrevToken
in interfaceXmlCursor
- Returns:
- true if there is a previous token; otherwise, false.
-
toNextToken
Description copied from interface:XmlCursor
Moves the cursor to the next token. When there are no more tokens available, hasNextToken returns false and toNextToken() returns NONE and does not move the cursor. Returns the token type of the token to the right of the cursor upon a successful move.- Specified by:
toNextToken
in interfaceXmlCursor
- Returns:
- The token type for the next token if the cursor was moved; otherwise, NONE.
-
toPrevToken
Description copied from interface:XmlCursor
Moves the cursor to the previous token. When there is no previous token, returns NONE, otherwise returns the token to the left of the new position of the cursor.- Specified by:
toPrevToken
in interfaceXmlCursor
- Returns:
- The token type for the previous token if the cursor was moved; otherwise, NONE.
-
toFirstContentToken
Description copied from interface:XmlCursor
Moves the cursor to the first token in the content of the current START or STARTDOC. That is, the first token after all ATTR and NAMESPACE tokens associated with this START.
If the current token is not a START or STARTDOC, the cursor is not moved and NONE is returned. If the current START or STARTDOC has no content, the cursor is moved to the END or ENDDOC token.
- Specified by:
toFirstContentToken
in interfaceXmlCursor
- Returns:
- The new current token type.
-
toEndToken
Description copied from interface:XmlCursor
Moves the cursor to the END or ENDDOC token corresponding to the current START or STARTDOC, and returns END or ENDDOC.
If the current token is not a START or STARTDOC, the cursor is not moved and NONE is returned.
- Specified by:
toEndToken
in interfaceXmlCursor
- Returns:
- The new current token type.
-
toNextChar
public int toNextChar(int cch)Description copied from interface:XmlCursor
Moves the cursor forward by the specified number of characters, and stops at the next non-TEXT token. Returns the number of characters actually moved across, which is guaranteed to be less than or equal to maxCharacterCount. If there is no further text, or if there is no text at all, returns zero.
Note this does not dive into attribute values, comment contents, processing instruction contents, etc., but only content text.
You can pass maxCharacterCount < 0 to move over all the text to the right. This has the same effect as toNextToken, but returns the amount of text moved over.
- Specified by:
toNextChar
in interfaceXmlCursor
- Parameters:
cch
- The maximum number of characters by which the cursor should be moved.- Returns:
- The actual number of characters by which the cursor was moved; 0 if the cursor was not moved.
-
toPrevChar
public int toPrevChar(int cch)Description copied from interface:XmlCursor
Moves the cursor backwards by the number of characters given. Has similar characteristics to thetoNextChar
method.- Specified by:
toPrevChar
in interfaceXmlCursor
- Parameters:
cch
- The maximum number of characters by which the cursor should be moved.- Returns:
- The actual number of characters by which the cursor was moved; 0 if the cursor was not moved.
-
___toNextSibling
public boolean ___toNextSibling() -
toNextSibling
public boolean toNextSibling()Description copied from interface:XmlCursor
Moves the cursor to the next sibling element, or returns false and does not move the cursor if there is no next sibling element. (By definition the position of an element is the same as the position of its START token.)If the current token is not s START, the cursor will be moved to the next START without moving out of the scope of the current element.
- Specified by:
toNextSibling
in interfaceXmlCursor
- Returns:
- true if the cursor was moved; otherwise, false.
-
toPrevSibling
public boolean toPrevSibling()Description copied from interface:XmlCursor
Moves the cursor to the previous sibling element, or returns false and does not move the cursor if there is no previous sibling element. (By definition the position of an element is the same as the position of its START token.)- Specified by:
toPrevSibling
in interfaceXmlCursor
- Returns:
- true if the cursor was moved; otherwise, false.
-
toParent
public boolean toParent()Description copied from interface:XmlCursor
Moves the cursor to the parent element or STARTDOC, or returns false and does not move the cursor if there is no parent.
Works if you're in attributes or content. Returns false only if at STARTDOC. Note that the parent of an END token is the corresponding START token.
-
toFirstChild
public boolean toFirstChild()Description copied from interface:XmlCursor
Moves the cursor to the first child element, or returns false and does not move the cursor if there are no element children.
If the cursor is not currently in an element, it moves into the first child element of the next element.
- Specified by:
toFirstChild
in interfaceXmlCursor
- Returns:
- true if the cursor was moved; otherwise, false.
-
toLastChild
public boolean toLastChild()Description copied from interface:XmlCursor
Moves the cursor to the last element child, or returns false and does not move the cursor if there are no element children.- Specified by:
toLastChild
in interfaceXmlCursor
- Returns:
- true if the cursor was moved; otherwise, false.
-
toChild
Description copied from interface:XmlCursor
Moves the cursor to the first child element of the specified name in no namespace. -
toChild
Description copied from interface:XmlCursor
Moves the cursor to the first child element of the specified name in the specified namespace. -
toChild
Description copied from interface:XmlCursor
Moves the cursor to the first child element of the specified qualified name. -
toChild
public boolean toChild(int index)Description copied from interface:XmlCursor
Moves the cursor to the child element specified by index. -
toChild
Description copied from interface:XmlCursor
Moves the cursor to the specified index child element of the specified name, where that element is the . -
toNextSibling
Description copied from interface:XmlCursor
Moves the cursor to the next sibling element of the specified name in no namespace.- Specified by:
toNextSibling
in interfaceXmlCursor
- Parameters:
name
- The name of the element to move the cursor to.- Returns:
- true if the cursor was moved; otherwise, false.
-
toNextSibling
Description copied from interface:XmlCursor
Moves the cursor to the next sibling element of the specified name in the specified namespace.- Specified by:
toNextSibling
in interfaceXmlCursor
- Parameters:
namespace
- The namespace URI for the element to move the cursor to.name
- The name of the element to move the cursor to.- Returns:
- true if the cursor was moved; otherwise, false.
-
toNextSibling
Description copied from interface:XmlCursor
Moves the cursor to the next sibling element of the specified qualified name.- Specified by:
toNextSibling
in interfaceXmlCursor
- Parameters:
name
- The name of the element to move the cursor to.- Returns:
- true if the cursor was moved; otherwise, false.
-
toFirstAttribute
public boolean toFirstAttribute()Description copied from interface:XmlCursor
Moves the cursor to the first attribute of this element, or returns false and does not move the cursor if there are no attributes. The order of attributes is arbitrary, but stable.
If the cursor is on a STARTDOC of a document-fragment, this method will move it to the first top level attribute if one exists.
xmlns attributes (namespace declarations) are not considered attributes by this function.
The cursor must be on a START or STARTDOC (in the case of a document fragment with top level attributes) for this method to succeed.
Example for looping through attributes:
XmlCursor cursor = ... //cursor on START or STARTDOC if (cursor.toFirstAttribute()) { do { // do something using attribute's name and value cursor.getName(); cursor.getTextValue(); } while (cursor.toNextAttribute()); }
- Specified by:
toFirstAttribute
in interfaceXmlCursor
- Returns:
- true if the cursor was moved; otherwise, false.
-
toLastAttribute
public boolean toLastAttribute()Description copied from interface:XmlCursor
Moves the cursor to the last attribute of this element, or returns false and does not move the cursor if there are no attributes. The order of attributes is arbitrary, but stable.
xmlns attributes (namespace declarations) are not considered attributes by this function.
The cursor must be on a START or STARTDOC for this method to succeed.
- Specified by:
toLastAttribute
in interfaceXmlCursor
- Returns:
- true if the cursor was moved; otherwise, false.
-
toNextAttribute
public boolean toNextAttribute()Description copied from interface:XmlCursor
Moves the cursor to the next sibling attribute, or returns false and does not move the cursor if there is no next sibling attribute. The order of attributes is arbitrary, but stable.
xmlns attributes (namespace declarations) are not considered attributes by this function.
The cursor must be on an attribute for this method to succeed.
- Specified by:
toNextAttribute
in interfaceXmlCursor
- Returns:
- true if the cursor was moved; otherwise, false.
- See Also:
XmlCursor.toFirstAttribute()
-
toPrevAttribute
public boolean toPrevAttribute()Description copied from interface:XmlCursor
Moves the cursor to the previous sibling attribute, or returns false and does not move the cursor if there is no previous sibling attribute. The order of attributes is arbitrary, but stable.
xmlns attributes (namespace declarations) are not considered attributes by this function.
The cursor must be on an attribute for this method to succeed.
- Specified by:
toPrevAttribute
in interfaceXmlCursor
- Returns:
- true if the cursor was moved; otherwise, false.
-
getAttributeText
Description copied from interface:XmlCursor
When at a START or STARTDOC, returns the attribute text for the given attribute. When not at a START or STARTDOC or the attribute does not exist, returns null.- Specified by:
getAttributeText
in interfaceXmlCursor
- Parameters:
attrName
- The name of the attribute whose value is requested.- Returns:
- The attribute's value if it has one; otherwise, null.
-
setAttributeText
Description copied from interface:XmlCursor
When at a START or STARTDOC, sets the attribute text for the given attribute. When not at a START or STARTDOC returns false. If the attribute does not exist, one is created.- Specified by:
setAttributeText
in interfaceXmlCursor
- Parameters:
attrName
- The name of the attribute whose value is being set.value
- The new value for the attribute.- Returns:
- true if the new value was set; otherwise, false.
-
removeAttribute
Description copied from interface:XmlCursor
When at a START or STARTDOC, removes the attribute with the given name.- Specified by:
removeAttribute
in interfaceXmlCursor
- Parameters:
attrName
- The name of the attribute that should be removed.- Returns:
- true if the attribute was removed; otherwise, false.
-
getTextValue
Description copied from interface:XmlCursor
Gets the text value of the current document, element, attribute, comment, procinst or text token.
When getting the text value of an element, non-text content such as comments and processing instructions are ignored and text is concatenated. For elements that have nested element children, this returns the concatenated text of all mixed content and the text of all the element children, recursing in first-to-last depthfirst order.
For attributes, including namespaces, this returns the attribute value.
For comments and processing instructions, this returns the text content of the comment or PI, not including the delimiting sequences <!-- -->, <? ?>. For a PI, the name of the PI is also not included.
The value of an empty tag is the empty string.
If the current token is END or ENDDOC, this throws an
IllegalStateException
.- Specified by:
getTextValue
in interfaceXmlCursor
- Returns:
- The text value of the current token if the token's type is START, STARTDOC, TEXT, ATTR, COMMENT, PROCINST, or NAMESPACE; null if the type is NONE.
-
getTextValue
public int getTextValue(char[] chars, int offset, int cch)Description copied from interface:XmlCursor
Copies the text value of the current document, element, attribute, comment, processing instruction or text token, counting right from this cursor's location up to maxCharacterCount, and copies the returned text into returnedChars.
When getting the text value of an element, non-text content such as comments and processing instructions are ignored and text is concatenated. For elements that have nested element children, this returns the concatenated text of all mixed content and the text of all the element children, recursing in first-to-last depthfirst order.
For attributes, including namespaces, this returns the attribute value.
For comments and processing instructions, this returns the text contents of the comment or PI, not including the delimiting sequences <!-- -->, <? ?>. For a PI, the text will not include the name of the PI.
If the current token is END or ENDDOC, this throws an
IllegalStateException
.
The value of an empty tag is the empty string.
- Specified by:
getTextValue
in interfaceXmlCursor
- Parameters:
chars
- A character array to hold the returned characters.offset
- The position within returnedChars to which the first of the returned characters should be copied.cch
- The maximum number of characters after this cursor's location to copy. A negative value specifies that all characters should be copied.- Returns:
- The actual number of characters copied; 0 if no characters were copied.
-
setTextValue
Description copied from interface:XmlCursor
Sets the text value of the XML at this cursor's location if that XML's token type is START, STARTDOC, ATTR, COMMENT or PROCINST.
For elements that have nested children this first removes all the content of the element and replaces it with the given text.
- Specified by:
setTextValue
in interfaceXmlCursor
- Parameters:
text
- The text to use as a new value.
-
setTextValue
public void setTextValue(char[] sourceChars, int offset, int length)Description copied from interface:XmlCursor
Sets the text value of the XML at this cursor's location (if that XML's token type is START, STARTDOC, ATTR, COMMENT or PROCINST) to the contents of the specified character array.
For elements that have nested children this first removes all the content of the element and replaces it with the given text.
- Specified by:
setTextValue
in interfaceXmlCursor
- Parameters:
sourceChars
- A character array containing the XML's new value.offset
- The position within sourceChars from which the first of the source characters should be copied.length
- The maximum number of characters to set as the XML's new value.
-
getChars
Description copied from interface:XmlCursor
Returns characters to the right of the cursor up to the next token. -
getChars
public int getChars(char[] chars, int offset, int cch)Description copied from interface:XmlCursor
Copies characters up to the specified maximum number, counting right from this cursor's location to the character at maxCharacterCount. The returned characters are added to returnedChars, with the first character copied to the offset position. The maxCharacterCount parameter should be less than or equal to the length of returnedChars minus offset. Copies a number of characters, which is either maxCharacterCount or the number of characters up to the next token, whichever is less.- Specified by:
getChars
in interfaceXmlCursor
- Parameters:
chars
- A character array to hold the returned characters.offset
- The position within returnedChars at which the first of the returned characters should be added.cch
- The maximum number of characters after this cursor's location to return.- Returns:
- The actual number of characters returned; 0 if no characters were returned or if the current token is not TEXT.
-
toStartDoc
public void toStartDoc()Description copied from interface:XmlCursor
Moves the cursor to the STARTDOC token, which is the root of the document.- Specified by:
toStartDoc
in interfaceXmlCursor
-
toEndDoc
public void toEndDoc()Description copied from interface:XmlCursor
Moves the cursor to the ENDDOC token, which is the end of the document. -
execQuery
Description copied from interface:XmlCursor
Executes the specified XQuery expression against the XML this cursor is in.
The query may be a String or a compiled query. You can precompile an XQuery expression using the XmlBeans.compileQuery method.
The root referred to by the expression should be given as a dot. The following is an example path expression:
XmlCursor results = cursor.execQuery("purchase-order/line-item[price <= 20.00]");
-
execQuery
Description copied from interface:XmlCursor
Executes the specified XQuery expression against the XML this cursor is in, and using the specified options.- Specified by:
execQuery
in interfaceXmlCursor
- Parameters:
query
- The XQuery expression to execute.options
- Options for the query. For example, you can call theXmlOptions.setXqueryCurrentNodeVar(String)
method to specify a particular name for the query expression variable that indicates the context node.
-
getDocChangeStamp
Description copied from interface:XmlCursor
Returns the current change stamp for the document the current cursor is in. This change stamp can be queried at a later point in time to find out if the document has changed.- Specified by:
getDocChangeStamp
in interfaceXmlCursor
- Returns:
- The change stamp for the document the current cursor is in.
-
setBookmark
Description copied from interface:XmlCursor
Sets a bookmark to the document at this cursor's location.The bookmark is attached to the token in the tree immediately after the cursor. If the tree is manipulated to move that object to a different place, the bookmark moves with it. If the tree is manipulated to delete that token from the tree, the bookmark is orphaned. Copy operations do not copy bookmarks.
- Specified by:
setBookmark
in interfaceXmlCursor
- Parameters:
bookmark
- The bookmark to set.
-
getBookmark
Description copied from interface:XmlCursor
Retrieves the bookmark with the specified key at this cursor's location. If there is no bookmark whose key is given by the specified key at the current position, null is returned. If thegetKey
method is not overridden on the bookmark, then the bookmark's class is used as the key.- Specified by:
getBookmark
in interfaceXmlCursor
- Parameters:
key
- The key for the bookmark to retrieve.- Returns:
- The requested bookmark; null if there is no bookmark corresponding to the specified key.
-
clearBookmark
Description copied from interface:XmlCursor
Clears the bookmark whose key is specified, if the bookmark exists at this cursor's location.- Specified by:
clearBookmark
in interfaceXmlCursor
- Parameters:
key
- The for the bookmark to clear.
-
getAllBookmarkRefs
Description copied from interface:XmlCursor
Retrieves all the bookmarks at this location, adding them to the specified collection. Bookmarks held by weak references are added to this collection as Weak referenced objects pointing to the bookmark.- Specified by:
getAllBookmarkRefs
in interfaceXmlCursor
- Parameters:
listToFill
- The collection that will contain bookmarks returned by this method.
-
removeXml
public boolean removeXml()Description copied from interface:XmlCursor
Removes the XML that is immediately after this cursor.For the TEXT, ATTR, NAMESPACE, COMMENT and PROCINST tokens, a single token is removed. For a START token, the corresponding element and all of its contents are removed. For all other tokens, this is a no-op. You cannot remove a STARTDOC.
The cursors located in the XML that was removed all collapse to the same location. All bookmarks in this XML will be orphaned.
-
removeXmlContents
public boolean removeXmlContents()Description copied from interface:XmlCursor
Removes the contents of the container (STARTDOC OR START) immediately after this cursor. For all other situations, returns false. Does not remove attributes or namspaces.- Specified by:
removeXmlContents
in interfaceXmlCursor
- Returns:
- true if anything was copied; otherwise, false.
-
removeChars
public int removeChars(int cch)Description copied from interface:XmlCursor
Removes characters up to the specified maximum number, counting right from this cursor's location to the character at maxCharacterCount. The space remaining from removing the characters collapses up to this cursor.- Specified by:
removeChars
in interfaceXmlCursor
- Parameters:
cch
- The maximum number of characters after this cursor's location to remove.- Returns:
- The actual number of characters removed.
-
insertChars
Description copied from interface:XmlCursor
Inserts the specified text immediately before this cursor's location.- Specified by:
insertChars
in interfaceXmlCursor
- Parameters:
text
- The text to insert.
-
insertElement
Description copied from interface:XmlCursor
Inserts an element immediately before this cursor's location, giving the element the specified qualified name.- Specified by:
insertElement
in interfaceXmlCursor
- Parameters:
name
- The qualified name for the element.
-
insertElement
Description copied from interface:XmlCursor
Inserts an element immediately before this cursor's location, giving the element the specified local name.- Specified by:
insertElement
in interfaceXmlCursor
- Parameters:
localName
- The local name for the new element.
-
insertElement
Description copied from interface:XmlCursor
Inserts a new element immediately before this cursor's location, giving the element the specified local name and associating it with specified namespace- Specified by:
insertElement
in interfaceXmlCursor
- Parameters:
localName
- The local name for the new element.uri
- The URI for the new element's namespace.
-
beginElement
Description copied from interface:XmlCursor
Inserts a new element around this cursor, giving the element the specified qualified name. After the element is inserted, this cursor is between its start and end. This cursor can then be used to insert additional XML into the new element.- Specified by:
beginElement
in interfaceXmlCursor
- Parameters:
name
- The qualified name for the new element.
-
beginElement
Description copied from interface:XmlCursor
Inserts a new element around this cursor, giving the element the specified local name. After the element is inserted, this cursor is between its start and end. This cursor can then be used to insert additional XML into the new element.- Specified by:
beginElement
in interfaceXmlCursor
- Parameters:
localName
- The local name for the new element.
-
beginElement
Description copied from interface:XmlCursor
Inserts a new element around this cursor, giving the element the specified local name and associating it with the specified namespace. After the element is inserted, this cursor is between its start and end. This cursor can then be used to insert additional XML into the new element.- Specified by:
beginElement
in interfaceXmlCursor
- Parameters:
localName
- The local name for the new element.uri
- The URI for the new element's namespace.
-
insertElementWithText
Description copied from interface:XmlCursor
Inserts a new element immediately before this cursor's location, giving the element the specified qualified name and content.- Specified by:
insertElementWithText
in interfaceXmlCursor
- Parameters:
name
- The qualified name for the new element.text
- The content for the new element.
-
insertElementWithText
Description copied from interface:XmlCursor
Inserts a new element immediately before this cursor's location, giving the element the specified local name and content.- Specified by:
insertElementWithText
in interfaceXmlCursor
- Parameters:
localName
- The local name for the new element.text
- The content for the new element.
-
insertElementWithText
Description copied from interface:XmlCursor
Inserts a new element immediately before this cursor's location, giving the element the specified local name, associating it with the specified namespace, and giving it the specified content.- Specified by:
insertElementWithText
in interfaceXmlCursor
- Parameters:
localName
- The local name for the new element.uri
- The URI for the new element's namespace.text
- The content for the new element.
-
insertAttribute
Description copied from interface:XmlCursor
Inserts a new attribute immediately before this cursor's location, giving it the specified local name.- Specified by:
insertAttribute
in interfaceXmlCursor
- Parameters:
localName
- The local name for the new attribute.
-
insertAttribute
Description copied from interface:XmlCursor
Inserts a new attribute immediately before this cursor's location, giving it the specified local name and associating it with the specified namespace.- Specified by:
insertAttribute
in interfaceXmlCursor
- Parameters:
localName
- The local name for the new attribute.uri
- The URI for the new attribute's namespace.
-
insertAttribute
Description copied from interface:XmlCursor
Inserts a new attribute immediately before this cursor's location, giving it the specified name.- Specified by:
insertAttribute
in interfaceXmlCursor
- Parameters:
name
- The local name for the new attribute.
-
insertAttributeWithValue
Description copied from interface:XmlCursor
Inserts a new attribute immediately before this cursor's location, giving it the specified value and name.- Specified by:
insertAttributeWithValue
in interfaceXmlCursor
- Parameters:
name
- The local name for the new attribute.value
- The value for the new attribute.
-
insertAttributeWithValue
Description copied from interface:XmlCursor
Inserts an attribute immediately before the cursor's location, giving it the specified name and value, and associating it with the specified namespace.- Specified by:
insertAttributeWithValue
in interfaceXmlCursor
- Parameters:
name
- The name for the new attribute.uri
- The URI for the new attribute's namespace.value
- The value for the new attribute.
-
insertAttributeWithValue
Description copied from interface:XmlCursor
Inserts an attribute immediately before the cursor's location, giving it the specified name and value.- Specified by:
insertAttributeWithValue
in interfaceXmlCursor
- Parameters:
name
- The name for the new attribute.value
- The value for the new attribute.
-
insertNamespace
Description copied from interface:XmlCursor
Inserts a namespace declaration immediately before the cursor's location, giving it the specified prefix and URI.- Specified by:
insertNamespace
in interfaceXmlCursor
- Parameters:
prefix
- The prefix for the namespace.namespace
- The URI for the namespace.
-
insertComment
Description copied from interface:XmlCursor
Inserts an XML comment immediately before the cursor's location, giving it the specified content.- Specified by:
insertComment
in interfaceXmlCursor
- Parameters:
text
- The new comment's content.
-
insertProcInst
Description copied from interface:XmlCursor
Inserts an XML processing instruction immediately before the cursor's location, giving it the specified target and text.- Specified by:
insertProcInst
in interfaceXmlCursor
- Parameters:
target
- The target for the processing instruction.text
- The new processing instruction's text.
-
dump
public void dump()Description copied from interface:XmlTokenSource
Prints to stdout the state of the document in which this token source is positioned. This is very implementation specific and may change at any time. Dump can be useful for debugging purposes. It is very different from the save methods which produce XML text which only approximates the actual state of the document.- Specified by:
dump
in interfaceXmlTokenSource
-