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


Java Node.getParentNode方法代码示例

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


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

示例1: iterator

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Creates an iterator which return's PropBagEx's for each child for the
 * path given<br>
 * E.g.<br>
 * /path/node/item<br>
 * Will iterate over all the "item" nodes.
 * 
 * @param path
 * @return
 */
public PropBagIterator iterator(final String path)
{
	checkNotAttribute(path);
	ensureRoot();

	String name = null;
	Node parent = null;

	final Node node = getNodeHelper(path, false, false);
	if( node != null )
	{
		parent = node.getParentNode();

		// see Jira Defect TLE-1293 :
		// http://apps.dytech.com.au/jira/browse/TLE-1293
		name = DOMHelper.stripNamespace(node.getNodeName());
		if( path.endsWith(WILD) )
		{
			name = WILD;
		}

	}
	return new PropBagIterator(parent, node, name, m_elRoot);
}
 
开发者ID:equella,项目名称:Equella,代码行数:35,代码来源:PropBagEx.java

示例2: getChildElements

import org.w3c.dom.Node; //导入方法依赖的package包/类
public static List<Element> getChildElements(Element parent, String tagName) {
    if (null == parent) {
        return null;
    }
    NodeList nodes = parent.getElementsByTagName(tagName);
    List<Element> elements = new ArrayList<Element>();

    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node.getParentNode() == parent) {
            elements.add((Element) node);
        }
    }

    return elements;
}
 
开发者ID:aliyun,项目名称:fc-java-sdk,代码行数:17,代码来源:XmlUtils.java

示例3: collectCDATASections

import org.w3c.dom.Node; //导入方法依赖的package包/类
private static void collectCDATASections(Node node, Set<String> cdataQNames) {
    if (node instanceof CDATASection) {
        Node parent = node.getParentNode();
        if (parent != null) {
            String uri = parent.getNamespaceURI();
            if (uri != null) {
                cdataQNames.add("{" + uri + "}" + parent.getNodeName()); //NOI18N
            } else {
                cdataQNames.add(parent.getNodeName());
            }
        }
    }
    
    NodeList children = node.getChildNodes();
    for(int i = 0; i < children.getLength(); i++) {
        collectCDATASections(children.item(i), cdataQNames);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:XMLUtil.java

示例4: getNextLogicalSibling

import org.w3c.dom.Node; //导入方法依赖的package包/类
private Node getNextLogicalSibling(Node n) {
    Node next = n.getNextSibling();
    // If "n" has no following sibling and its parent is an entity reference node we
    // need to continue the search through the following siblings of the entity
    // reference as these are logically siblings of the given node.
    if (next == null) {
        Node parent = n.getParentNode();
        while (parent != null && parent.getNodeType() == Node.ENTITY_REFERENCE_NODE) {
            next = parent.getNextSibling();
            if (next != null) {
                break;
            }
            parent = parent.getParentNode();
        }
    }
    return next;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:ElementImpl.java

示例5: getIdentifier

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Returns a previously registered element with the specified
 * identifier name, or null if no element is registered.
 *
 * @see #putIdentifier
 * @see #removeIdentifier
 */
public Element getIdentifier(String idName) {

    if (needsSyncData()) {
        synchronizeData();
    }

    if (identifiers == null) {
        return null;
    }
    Element elem = (Element) identifiers.get(idName);
    if (elem != null) {
        // check that the element is in the tree
        Node parent = elem.getParentNode();
        while (parent != null) {
            if (parent == this) {
                return elem;
            }
            parent = parent.getParentNode();
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:CoreDocumentImpl.java

示例6: nextNode

import org.w3c.dom.Node; //导入方法依赖的package包/类
Node nextNode(Node node, boolean visitChildren) {

        if (node == null) return null;

        Node result;
        if (visitChildren) {
            result = node.getFirstChild();
            if (result != null) {
                return result;
            }
        }

        // if hasSibling, return sibling
        result = node.getNextSibling();
        if (result != null) {
            return result;
        }


        // return parent's 1st sibling.
        Node parent = node.getParentNode();
        while (parent != null
               && parent != fDocument
                ) {
            result = parent.getNextSibling();
            if (result != null) {
                return result;
            } else {
                parent = parent.getParentNode();
            }

        } // while (parent != null && parent != fRoot) {

        // end of list, return null
        return null;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:RangeImpl.java

示例7: getPositionRelativeToDocumentElement

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Checks whether a Comment or ProcessingInstruction is before or after the
 * document element. This is needed for prepending or appending "\n"s.
 *
 * @param currentNode
 *            comment or pi to check
 * @return NODE_BEFORE_DOCUMENT_ELEMENT,
 *         NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT or
 *         NODE_AFTER_DOCUMENT_ELEMENT
 * @see #NODE_BEFORE_DOCUMENT_ELEMENT
 * @see #NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT
 * @see #NODE_AFTER_DOCUMENT_ELEMENT
 */
private int getPositionRelativeToDocumentElement(Node currentNode) {
    if (currentNode == null) {
        return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
    }

    Document doc = currentNode.getOwnerDocument();

    if (currentNode.getParentNode() != doc) {
        return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
    }

    Element documentElement = doc.getDocumentElement();

    if (documentElement == null) {
        return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
    }

    if (documentElement == currentNode) {
        return NODE_NOT_BEFORE_OR_AFTER_DOCUMENT_ELEMENT;
    }

    for (Node x = currentNode; x != null; x = x.getNextSibling()) {
        if (x == documentElement) {
            return NODE_BEFORE_DOCUMENT_ELEMENT;
        }
    }

    return NODE_AFTER_DOCUMENT_ELEMENT;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:43,代码来源:XMLSignatureInputDebugger.java

示例8: validate

import org.w3c.dom.Node; //导入方法依赖的package包/类
/** Traverse the DOM and fire events to the schema validator. */
private void validate(Node node) {
    final Node top = node;
    // Performs a non-recursive traversal of the DOM. This
    // will avoid a stack overflow for DOMs with high depth.
    while (node != null) {
        beginNode(node);
        Node next = node.getFirstChild();
        while (next == null) {
            finishNode(node);
            if (top == node) {
                break;
            }
            next = node.getNextSibling();
            if (next == null) {
                node = node.getParentNode();
                if (node == null || top == node) {
                    if (node != null) {
                        finishNode(node);
                    }
                    next = null;
                    break;
                }
            }
        }
        node = next;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:29,代码来源:DOMValidatorHelper.java

示例9: getElementAncestor

import org.w3c.dom.Node; //导入方法依赖的package包/类
Node getElementAncestor (Node currentNode){
    Node parent = currentNode.getParentNode();
    if (parent != null) {
        short type = parent.getNodeType();
        if (type == Node.ELEMENT_NODE) {
            return parent;
        }
        return getElementAncestor(parent);
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:NodeImpl.java

示例10: getPreviousSibling

import org.w3c.dom.Node; //导入方法依赖的package包/类
/** Internal function.
 *  Return the previousSibling Node, from the input node
 *  after applying filter, whatToshow.
     *  NEVER TRAVERSES ABOVE THE SPECIFIED ROOT NODE.
 *  The current node is not consulted or set.
 */
Node getPreviousSibling(Node node, Node root) {

    if (node == null || node == root) return null;

    Node newNode = node.getPreviousSibling();
    if (newNode == null) {

        newNode = node.getParentNode();
        if (newNode == null || newNode == root)  return null;

        int parentAccept = acceptNode(newNode);

        if (parentAccept==NodeFilter.FILTER_SKIP) {
            return getPreviousSibling(newNode, root);
        }

        return null;
    }

    int accept = acceptNode(newNode);

    if (accept == NodeFilter.FILTER_ACCEPT)
        return newNode;
    else
    if (accept == NodeFilter.FILTER_SKIP) {
        Node fChild =  getLastChild(newNode);
        if (fChild == null) {
            return getPreviousSibling(newNode, root);
        }
        return fChild;
    }
    else
    //if (accept == NodeFilter.REJECT_NODE)
    {
        return getPreviousSibling(newNode, root);
    }

}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:TreeWalkerImpl.java

示例11: fillNamespaceContext

import org.w3c.dom.Node; //导入方法依赖的package包/类
private void fillNamespaceContext() {
    if (fRoot != null) {
        Node currentNode = fRoot.getParentNode();
        while (currentNode != null) {
            if (Node.ELEMENT_NODE == currentNode.getNodeType()) {
                NamedNodeMap attributes = currentNode.getAttributes();
                final int attrCount = attributes.getLength();
                for (int i = 0; i < attrCount; ++i) {
                    Attr attr = (Attr) attributes.item(i);
                    String value = attr.getValue();
                    if (value == null) {
                        value = XMLSymbols.EMPTY_STRING;
                    }
                    fillQName(fAttributeQName, attr);
                    // REVISIT: Should we be looking at non-namespace attributes
                    // for additional mappings? Should we detect illegal namespace
                    // declarations and exclude them from the context? -- mrglavas
                    if (fAttributeQName.uri == NamespaceContext.XMLNS_URI) {
                        // process namespace attribute
                        if (fAttributeQName.prefix == XMLSymbols.PREFIX_XMLNS) {
                            declarePrefix0(fAttributeQName.localpart, value.length() != 0 ? fSymbolTable.addSymbol(value) : null);
                        }
                        else {
                            declarePrefix0(XMLSymbols.EMPTY_STRING, value.length() != 0 ? fSymbolTable.addSymbol(value) : null);
                        }
                    }
                }

            }
            currentNode = currentNode.getParentNode();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:34,代码来源:DOMValidatorHelper.java

示例12: getAttributeValue

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Gets a named attribute value of a node if one exists.
 * 
 * @param attrName the attribute local name. The attribute object has not been constructed at this point.
 * @param parentNode the parent Node object, allows a string representation of a relative path snippet of the
 *           attribute to be constructed.
 * @return the value of the attribute if it exists.
 */
public String getAttributeValue(String attrName,
                                Node parentNode) {
   String value = null;
   int maxDepth = maxValuePathDepth;

   for (int i = 0; i < maxDepth; i++) {
      if (attributeValueMap.containsKey(attrName)) {
         List<String> currentValue = attributeValueMap.get(attrName);
         if (currentValue != null && currentValue.size() > 1) {
            // multiple values - remove to cycle through
            if (currentValue.get(0) != null) {
               value = (String) currentValue.remove(0);
               currentValue.add(null);
            }
         }
         else if (currentValue != null && currentValue.size() > 0) {
            value = (String) currentValue.get(0);
         }
      }
      // construct a string representation of a path snippet of the
      // attribute to attempt a more granular match. A more granular
      // match will overwrite a less granular match.
      if (parentNode != null) {
         String parentNodeName = getNodeName(parentNode);
         attrName = parentNodeName + "." + attrName;
         parentNode = parentNode.getParentNode();
      }
      else {
         break;
      }
   }
   return value;
}
 
开发者ID:mqsysadmin,项目名称:dpdirect,代码行数:42,代码来源:SchemaLoader.java

示例13: traverseFragment

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Perform a pre-order traversal non-recursive style.
 *
 * In contrast to the traverse() method this method will not issue
 * startDocument() and endDocument() events to the SAX listener.
 *
 * @param pos Node in the tree where to start traversal
 *
 * @throws TransformerException
 */
public void traverseFragment(Node pos) throws org.xml.sax.SAXException
{
  Node top = pos;

  while (null != pos)
  {
    startNode(pos);

    Node nextNode = pos.getFirstChild();

    while (null == nextNode)
    {
      endNode(pos);

      if (top.equals(pos))
        break;

      nextNode = pos.getNextSibling();

      if (null == nextNode)
      {
        pos = pos.getParentNode();

        if ((null == pos) || (top.equals(pos)))
        {
          if (null != pos)
            endNode(pos);

          nextNode = null;

          break;
        }
      }
    }

    pos = nextNode;
  }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:49,代码来源:TreeWalker.java

示例14: getChildElements

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Gets the immediately child elements list from the parent element.
 *
 * @param parent the parent element in the element tree
 * @param tagName the specified tag name
 * @return the NOT NULL immediately child elements list
 */
public static List<Element> getChildElements(Element parent, String tagName) {
    NodeList nodes = parent.getElementsByTagName(tagName);
    List<Element> elements = new ArrayList<Element>();

    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (node instanceof Element && node.getParentNode() == parent) {
            elements.add((Element) node);
        }
    }

    return elements;
}
 
开发者ID:1991wangliang,项目名称:pay,代码行数:21,代码来源:XmlUtils.java

示例15: getChild

import org.w3c.dom.Node; //导入方法依赖的package包/类
/**
 * Returns the child element with the given name or <code>null</code> if it doesn't exist.
 *
 * @param name The child's name
 * @return the child element or <code>null</code>
 */
public DomElement getChild(String name) {
	NodeList list = e.getElementsByTagName(name);
	if (list.getLength() == 0)
		return null;
	for (int i = 0, j = list.getLength(); i < j; i++) {
		Node item = list.item(i);
		if (item.getParentNode() == e)
			return new DomElement((Element) item);
	}
	return null;
}
 
开发者ID:kawaiiDango,项目名称:pScrobbler,代码行数:18,代码来源:DomElement.java


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