本文整理了Java中org.w3c.dom.Node.compareDocumentPosition()
方法的一些代码示例,展示了Node.compareDocumentPosition()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Node.compareDocumentPosition()
方法的具体详情如下:
包路径:org.w3c.dom.Node
类名称:Node
方法名:compareDocumentPosition
[英]Compares the reference node, i.e. the node on which this method is being called, with a node, i.e. the one passed as a parameter, with regard to their position in the document and according to the document order.
[中]根据引用节点在文档中的位置和文档顺序,将引用节点(即调用此方法的节点)与节点(即作为参数传递的节点)进行比较。
代码示例来源:origin: pmd/pmd
@SuppressWarnings("PMD.AvoidUsingShortType")
@Override
public short compareDocumentPosition(org.w3c.dom.Node other) throws DOMException {
return node.compareDocumentPosition(other);
}
代码示例来源:origin: robovm/robovm
if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
代码示例来源:origin: robovm/robovm
if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
代码示例来源:origin: robovm/robovm
if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
代码示例来源:origin: robovm/robovm
if ((node.compareDocumentPosition(nextSibling)&Node.DOCUMENT_POSITION_CONTAINED_BY)==0) {
throw new IllegalArgumentException("Cannot create a DOMResult when the nextSibling is not contained by the node.");
代码示例来源:origin: fbacchella/jrds
/**
* @param other
* @return
* @throws org.w3c.dom.DOMException
* @see org.w3c.dom.Node#compareDocumentPosition(org.w3c.dom.Node)
*/
public short compareDocumentPosition(Node other) {
return parent.compareDocumentPosition(other);
}
代码示例来源:origin: org.jboss.ws.native/jbossws-native-core
public short compareDocumentPosition(Node other) throws DOMException
{
return this.domNode.compareDocumentPosition(other);
}
代码示例来源:origin: xyz.cofe/common
@Override
public short compareDocumentPosition(Node other) throws DOMException {
return node.compareDocumentPosition(other);
}
代码示例来源:origin: org.apache.axis2/axis2-saaj
public final short compareDocumentPosition(org.w3c.dom.Node other) throws DOMException {
return target.compareDocumentPosition(other);
}
代码示例来源:origin: apache/axis2-java
public final short compareDocumentPosition(org.w3c.dom.Node other) throws DOMException {
return target.compareDocumentPosition(other);
}
代码示例来源:origin: org.vx68k.quercus/quercus
public short compareDocumentPosition(DOMNode other)
throws DOMException
{
try {
return _delegate.compareDocumentPosition(other.getDelegate());
}
catch (org.w3c.dom.DOMException ex) {
throw wrap(ex);
}
}
代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite
/**
* Runs the test case.
* @throws Throwable Any uncaught exception causes test to fail
*/
public void runTest() throws Throwable {
Document doc;
NodeList elemList;
Element elemName;
Node entRef;
int elementPosition;
int entRefPosition;
doc = (Document) load("hc_staff", false);
elemList = doc.getElementsByTagName("var");
elemName = (Element) elemList.item(2);
entRef = elemName.getFirstChild();
elementPosition = (int) elemName.compareDocumentPosition(entRef);
assertEquals("nodecomparedocumentpositionIsContainedFollowing25", 20, elementPosition);
entRefPosition = (int) entRef.compareDocumentPosition(elemName);
assertEquals("nodecomparedocumentpositionContainsPRECEDING25", 10, entRefPosition);
}
/**
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* Returns the last selection range in the current document, by document position.
* @return the last selection range in the current document, by document position
*/
private Range getLastRange() {
// avoid concurrent modification exception
final List<Range> ranges = new ArrayList<>(getRanges());
Range last = null;
for (final Range range : ranges) {
if (last == null) {
last = range;
}
else {
final org.w3c.dom.Node lastStart = last.getStartContainer();
final org.w3c.dom.Node rangeStart = range.getStartContainer();
if ((lastStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_FOLLOWING) != 0) {
last = range;
}
}
}
return last;
}
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
/**
* Returns the first selection range in the current document, by document position.
* @return the first selection range in the current document, by document position
*/
private Range getFirstRange() {
// avoid concurrent modification exception
final List<Range> ranges = new ArrayList<>(getRanges());
Range first = null;
for (final Range range : ranges) {
if (first == null) {
first = range;
}
else {
final org.w3c.dom.Node firstStart = first.getStartContainer();
final org.w3c.dom.Node rangeStart = range.getStartContainer();
if ((firstStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_PRECEDING) != 0) {
first = range;
}
}
}
return first;
}
代码示例来源:origin: HtmlUnit/htmlunit
/**
* Returns the first selection range in the current document, by document position.
* @return the first selection range in the current document, by document position
*/
private Range getFirstRange() {
// avoid concurrent modification exception
final List<Range> ranges = new ArrayList<>(getRanges());
Range first = null;
for (final Range range : ranges) {
if (first == null) {
first = range;
}
else {
final org.w3c.dom.Node firstStart = first.getStartContainer();
final org.w3c.dom.Node rangeStart = range.getStartContainer();
if ((firstStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_PRECEDING) != 0) {
first = range;
}
}
}
return first;
}
代码示例来源:origin: HtmlUnit/htmlunit
/**
* Returns the last selection range in the current document, by document position.
* @return the last selection range in the current document, by document position
*/
private Range getLastRange() {
// avoid concurrent modification exception
final List<Range> ranges = new ArrayList<>(getRanges());
Range last = null;
for (final Range range : ranges) {
if (last == null) {
last = range;
}
else {
final org.w3c.dom.Node lastStart = last.getStartContainer();
final org.w3c.dom.Node rangeStart = range.getStartContainer();
if ((lastStart.compareDocumentPosition(rangeStart) & Node.DOCUMENT_POSITION_FOLLOWING) != 0) {
last = range;
}
}
}
return last;
}
代码示例来源:origin: com.rackspace.eclipse.webtools.sourceediting/org.eclipse.wst.xml.xpath2.processor
private static int compare_node(NodeType a, NodeType b) {
Node nodeA = a.node_value();
Node nodeB = b.node_value();
if (nodeA == nodeB || nodeA.isSameNode(nodeB)) return 0;
Document docA = getDocument(nodeA);
Document docB = getDocument(nodeB);
if (docA != docB && ! docA.isSameNode(docB)) {
return compareDocuments(docA, docB);
}
short relation = nodeA.compareDocumentPosition(nodeB);
if ((relation & Node.DOCUMENT_POSITION_PRECEDING) != 0)
return 1;
if ((relation & Node.DOCUMENT_POSITION_FOLLOWING) != 0)
return -1;
throw new RuntimeException("Unexpected result from node comparison: " + relation);
}
代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite
/**
* Runs the test case.
* @throws Throwable Any uncaught exception causes test to fail
*/
public void runTest() throws Throwable {
Document doc;
DocumentFragment docFrag;
Element docElem;
Attr attr;
Node docFragChild;
int attrPosition;
int docFragChildPosition;
Node appendedChild;
Node attrNode;
doc = (Document) load("hc_staff", true);
docElem = doc.getDocumentElement();
docFrag = doc.createDocumentFragment();
attr = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:lang");
attrNode = docElem.setAttributeNodeNS(attr);
appendedChild = docFrag.appendChild(docElem);
docFragChild = docFrag.getFirstChild();
docFragChildPosition = (int) docFragChild.compareDocumentPosition(attr);
assertEquals("nodecomparedocumentpositionIsContainedFollows15", 20, docFragChildPosition);
attrPosition = (int) attr.compareDocumentPosition(docFragChild);
assertEquals("nodecomparedocumentpositionPRECEEDINGContains15", 10, attrPosition);
}
/**
代码示例来源:origin: net.sourceforge.htmlunit/htmlunit
return false;
final short startComparison = start.compareDocumentPosition(otherStart);
final boolean startNodeBefore = startComparison == 0
|| (startComparison & Node.DOCUMENT_POSITION_CONTAINS) != 0
final org.w3c.dom.Node end = range_.getEndContainer();
final org.w3c.dom.Node otherEnd = otherRange.getEndContainer();
final short endComparison = end.compareDocumentPosition(otherEnd);
final boolean endNodeAfter = endComparison == 0
|| (endComparison & Node.DOCUMENT_POSITION_CONTAINS) != 0
代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite
/**
* Runs the test case.
* @throws Throwable Any uncaught exception causes test to fail
*/
public void runTest() throws Throwable {
Document doc;
DocumentFragment docFrag;
Element docElem;
Node docFragChild;
int docFragPosition;
int docFragChildPosition;
Node appendedChild;
doc = (Document) load("hc_staff", true);
docElem = doc.getDocumentElement();
docFrag = doc.createDocumentFragment();
appendedChild = docFrag.appendChild(docElem);
docFragChild = docFrag.getFirstChild();
docFragPosition = (int) docFrag.compareDocumentPosition(docFragChild);
assertEquals("nodecomparedocumentpositionContainsPRECEDING14", 20, docFragPosition);
docFragChildPosition = (int) docFragChild.compareDocumentPosition(docFrag);
assertEquals("nodecomparedocumentpositionIsContainedFollowing14", 10, docFragChildPosition);
}
/**
内容来源于网络,如有侵权,请联系作者删除!