本文整理汇总了Java中org.apache.xmlbeans.XmlCursor.comparePosition方法的典型用法代码示例。如果您正苦于以下问题:Java XmlCursor.comparePosition方法的具体用法?Java XmlCursor.comparePosition怎么用?Java XmlCursor.comparePosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xmlbeans.XmlCursor
的用法示例。
在下文中一共展示了XmlCursor.comparePosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: moveSrcToDest
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param srcCurs
* @param destCurs
* @param fDontMoveIfSame
* @return
*/
private boolean moveSrcToDest (XmlCursor srcCurs, XmlCursor destCurs, boolean fDontMoveIfSame)
{
boolean fMovedSomething = true;
TokenType tt;
do
{
if (fDontMoveIfSame && srcCurs.isInSameDocument(destCurs) && (srcCurs.comparePosition(destCurs) == 0))
{
// If the source and destination are pointing at the same place then there's nothing to move.
fMovedSomething = false;
break;
}
// todo ***TLL*** Use replaceContents (when added) and eliminate children removes (see above todo).
if (destCurs.currentTokenType().isStartdoc())
{
destCurs.toNextToken();
}
// todo ***TLL*** Can Eric support notion of copy instead of me copying then moving???
XmlCursor copyCurs = copy(srcCurs);
copyCurs.moveXml(destCurs);
copyCurs.dispose();
tt = srcCurs.currentTokenType();
} while (!tt.isStart() && !tt.isEnd() && !tt.isEnddoc());
return fMovedSomething;
}
示例2: insertChild
import org.apache.xmlbeans.XmlCursor; //导入方法依赖的package包/类
/**
*
* @param childToMatch
* @param xmlToInsert
* @param addToType
*/
private void insertChild(XML childToMatch, Object xmlToInsert, int addToType)
{
XmlCursor curs = newCursor();
TokenType tt = curs.currentTokenType();
XmlCursor xmlChildCursor = childToMatch.newCursor();
if (tt.isStartdoc())
{
tt = curs.toFirstContentToken();
}
if (tt.isContainer())
{
tt = curs.toNextToken();
while (!tt.isEnd())
{
if (tt.isStart())
{
// See if this child is the same as the one thep passed in
if (curs.comparePosition(xmlChildCursor) == 0)
{
// Found it
if (addToType == APPEND_CHILD)
{
// Move the cursor to just past the end of this element
curs.toEndToken();
curs.toNextToken();
}
insertChild(curs, xmlToInsert);
break;
}
}
// Skip over child elements
if (tt.isStart())
{
tt = curs.toEndToken();
}
tt = curs.toNextToken();
}
}
xmlChildCursor.dispose();
curs.dispose();
}