当前位置: 首页>>代码示例>>Java>>正文


Java Node.getParent方法代码示例

本文整理汇总了Java中nu.xom.Node.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java Node.getParent方法的具体用法?Java Node.getParent怎么用?Java Node.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nu.xom.Node的用法示例。


在下文中一共展示了Node.getParent方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prependCopy

import nu.xom.Node; //导入方法依赖的package包/类
@Override
public void prependCopy(XomNode node) throws XmlBuilderException {
    final Node wrappedNode = node.getNode();
    if (!(wrappedNode instanceof Element)) {
        throw new XmlBuilderException("Unable to copy non-element node " + node);
    }
    final ParentNode parent = wrappedNode.getParent();
    if (null == parent) {
        throw new XmlBuilderException("Unable to prepend - no parent found of " + node);
    }
    try {
        final int prependIndex = parent.indexOf(wrappedNode);
        final Node copiedNode = wrappedNode.copy();
        parent.insertChild(copiedNode, prependIndex);
    } catch (IllegalAddException iae) {
        throw new XmlBuilderException("Unable to append an copied element to " + parent, iae);
    }
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:19,代码来源:XomNavigator.java

示例2: moveToParentBefore

import nu.xom.Node; //导入方法依赖的package包/类
public Node moveToParentBefore(
  Node pTargetParentNode
, Node pMovingNode
, Node pPositionBeforeTargetParentsChildNode
) {
  // mDocControl in context of pTargetParentNode
  mDocControl.setDocumentModifiedCount();
  //If this is being moved FROM another document, update the FROM document's modified count
  if(pMovingNode.getDocument() != pTargetParentNode.getDocument()){
    DocControl.setDocumentModified(pMovingNode);
  }

  // The SiblingChild should already be attached to Parent element - so this is belt & braces check
  if (pPositionBeforeTargetParentsChildNode != null && pPositionBeforeTargetParentsChildNode.getParent() != pTargetParentNode) {
    throw new ExInternal("insertBefore error, the sibling is not a child of this node");
  }

  //Detach from parent
  pMovingNode.detach();

  int lTargetPosition = ((ParentNode) pTargetParentNode).indexOf(pPositionBeforeTargetParentsChildNode);
  ((ParentNode) pTargetParentNode).insertChild(pMovingNode, lTargetPosition);

  return pMovingNode;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:26,代码来源:ActuateReadWrite.java

示例3: remove

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Remove (i.e. detach) pNode from its parent. pNode will remain as an unattached node with no parent Element or
 * owning Document.
 * @param pNode The Node to remove.
 * @return pNode.
 * @throws ExInternal If the node cannot be removed because it is a Document node or root Element.
 */
public Node remove(Node pNode)
throws ExInternal {
  mDocControl.setDocumentModifiedCount();

  if(pNode instanceof Document){
    throw new ExInternal("The Document node cannot be removed.");
  } else if (pNode.getParent() instanceof Document){
    throw new ExInternal("The root element cannot be removed: " + getAbsolute(pNode));
  }

  //Detaching from parent is effectively a removal
  pNode.detach();

  if(pNode instanceof Element){
    mDocControl.refIndexRemoveRecursive((Element) pNode);
  }

  return pNode;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:27,代码来源:ActuateReadWrite.java

示例4: replaceWith

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Replaces pNode with pNewNode.
 * @param pNode The Node to replace.
 * @param pNewNode The Node to replace pNode with.
 * @return pNewNode
 */
public Node replaceWith(Node pNode, Node pNewNode) {
  mDocControl.setDocumentModifiedCount();

  //If pNewNode is being moved FROM another document, update the FROM document's modified count
  if(pNode.getDocument() != pNewNode.getDocument()){
    DocControl.setDocumentModified(pNewNode);
  }

  pNewNode.detach();

  ParentNode lParent = pNode.getParent();
  lParent.replaceChild(pNode, pNewNode);

  return pNewNode;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:22,代码来源:ActuateReadWrite.java

示例5: getNextSiblingOrNull

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Get the next sibling of pNode, in document order. Returns null if pNode has no following siblings.<br/>
 * XPath equivalent: <code>./following-sibling::*[1]</code> or <code>./following-sibling::node()[1]</code>
 * @param pNode The target Element.
 * @param pElementsOnly If true, only considers Elements. If false, considers all nodes.
 * @return pNode's next sibling, or null.
 */
public Node getNextSiblingOrNull(Node pNode, boolean pElementsOnly){
  ParentNode lParent = pNode.getParent();
  if(lParent == null){
    return null;
  }
  int lIndex = lParent.indexOf(pNode);
  while(lIndex < lParent.getChildCount() - 1){
    Node lNextSibling = lParent.getChild(++lIndex);
    //avoid non-Element siblings
    if(lNextSibling instanceof Element || !pElementsOnly) {
      return lNextSibling;
    }
  }
  return null;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:23,代码来源:ActuateReadOnly.java

示例6: getPreviousSiblingOrNull

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Get the previous sibling of pNode, in document order. Returns null if pNode has no previous siblings.<br/>
 * XPath equivalent: <code>./preceding-sibling::*[1]</code> or <code>./preceding-sibling::node()[1]</code>
 * @param pNode The target Element.
 * @param pElementsOnly If true, only considers Elements. If false, considers all nodes.
 * @return pNode's previous sibling, or null.
 */
public Node getPreviousSiblingOrNull(Node pNode, boolean pElementsOnly) {
  ParentNode lParent = pNode.getParent();
  if(lParent == null){
    return null;
  }
  int lIndex = lParent.indexOf(pNode);
  while(lIndex > 0){
    Node lNextSibling = lParent.getChild(--lIndex);
    //Avoid non-Element siblings
    if(lNextSibling instanceof Element || !pElementsOnly) {
      return lNextSibling;
    }
  }
  return null;
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:23,代码来源:ActuateReadOnly.java

示例7: getPerfectRef

import nu.xom.Node; //导入方法依赖的package包/类
public final String getPerfectRef(final Node pNode)
  throws ExInternal
{
  StringBuffer lStringBuffer= new StringBuffer();
  if(!(pNode instanceof Element)) {
    throw new ExInternal("non-Element passed to getPefectRef()");
  }
  Node lNode = pNode;
  while(lNode != null && DOM.NodeType.getNodeType(lNode) == DOM.NodeType.ELEMENT) {
    lStringBuffer.append(getRef(pNode)).append("/");
    lNode=lNode.getParent();
  }
  if(lNode != null && DOM.NodeType.getNodeType(lNode) == DOM.NodeType.DOCUMENT) {
    lStringBuffer.append("*DOC*");
  }
  return lStringBuffer.toString();
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:18,代码来源:ActuateReadOnly.java

示例8: wrap

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Converts a xom node into something readable by Saxon
 * @param node
 * @param config
 * @return
 */
static NodeInfo wrap(Node node, Configuration config) {
	if (node == null) 
		throw new IllegalArgumentException("node must not be null"); //$NON-NLS-1$
	if (node instanceof DocType)
		throw new IllegalArgumentException("DocType can't be queried by XQuery/XPath"); //$NON-NLS-1$
	
	Node root = node;
	while (root.getParent() != null) {
		root = root.getParent();
	}

	DocumentWrapper docWrapper = new DocumentWrapper(root, root.getBaseURI(), config);
	
	return docWrapper.wrap(node);
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:22,代码来源:XQueryEvaluator.java

示例9: getAbsolute

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Gets a simple path representation of the absolute path to this node from the root of its owning document.
 * Element names will include namespace prefixes.
 * E.g. /ROOT/LEVEL1/LEVEL2
 * @param pNode The Element to get a path for.
 * @return String representation of the Element's path.
 */
public String getAbsolute(Node pNode) {
  StringBuilder path = new StringBuilder();
  Node node = pNode;
  while ((node != null) && (node instanceof Element)) {
    path.insert(0, ((Element) node).getQualifiedName());
    path.insert(0,"/");
    node = node.getParent();
  }
  return path.toString();
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:18,代码来源:ActuateReadOnly.java

示例10: getRelativeDownToOrNull

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Gets a simple path representation of the path to pNestedNode from pNode.
 * @param pNode The context (parent) node.
 * @param pNestedNode The node to get the path for, relative to pNode.
 * @return String representation of the Element's path.
 */
public String getRelativeDownToOrNull(Node pNode, Node pNestedNode) {

  if(pNode==pNestedNode) {
    return ".";
  }

  if(!(pNestedNode instanceof Element) || !(pNode instanceof Element) ) {
    return null;
  }

  // Loop for each nested level (bottom up)
  StringBuffer path = new StringBuffer();
  Node node = pNestedNode;
  String lSep = "";
  TRAVERSE_LOOP: do{
    // Record nested node name
    path.insert(0,lSep);
    path.insert(0,((Element) node).getQualifiedName());
    lSep="/";

    // Advance to next level
    node = node.getParent();
    //We reached the top without finding pNode; assume pNestedNode is not a child of pNode and return null
    if(node instanceof Document){
      return null;
    }
    // When node not a true nested node
    if(node==null) {
      return null;
    }

  // Exit loop when parent located
  } while(node!=pNode);

  // Return relative path
  return path.toString();

}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:45,代码来源:ActuateReadOnly.java

示例11: getSiblingIndex

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Gets the position of this Node within its parent.
 * @param pNode
 * @return The node's position within its parent.
 */
public int getSiblingIndex(Node pNode) {
  if(pNode.getParent() != null){
    return pNode.getParent().indexOf(pNode);
  } else {
    throw new ExInternal("pNode does not have a parent in getSiblingIndex");
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:13,代码来源:ActuateReadOnly.java

示例12: getParentOrNull

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Gets the parent Element of pNode. If pNode is a root element or unattached, this method returns null.
 * @param pNode The target Node.
 * @return pNode's parent Element, or null.
 */
public Node getParentOrNull(Node pNode) {
  Node lParent = pNode.getParent();
  if(lParent==null || lParent instanceof Document) {
    return null;
  } else {
    return lParent;
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:14,代码来源:ActuateReadOnly.java

示例13: getParentOrSelf

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Gets the parent Element of pNode. If pNode is a root element or unattached, pNode is returned.
 * @param pNode The target Node.
 * @return pNode's parent Element, or pNode if it has none.
 */
public Node getParentOrSelf(Node pNode) {
  Node lParent = pNode.getParent();
  if(lParent==null || lParent instanceof Document) {
    return pNode;
  }
  else {
    return lParent;
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:15,代码来源:ActuateReadOnly.java

示例14: DocumentWrapper

import nu.xom.Node; //导入方法依赖的package包/类
/**
 * Create a Saxon wrapper for a XOM root node
 * 
 * @param root
 *            The XOM root node
 * @param baseURI
 *            The base URI for all the nodes in the tree
 * @param config
 *            The configuration which defines the name pool used for all
 *            names in this tree
 */
public DocumentWrapper(Node root, String baseURI, Configuration config) {
	super(root, null, 0);
	if (root.getParent() != null) 
		throw new IllegalArgumentException("root node must not have a parent node");
	this.baseURI = baseURI;
	this.docWrapper = this;
	setConfiguration(config);
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:20,代码来源:DocumentWrapper.java


注:本文中的nu.xom.Node.getParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。