本文整理匯總了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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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);
}
}
示例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();
}
}
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}