本文整理汇总了Java中mf.org.w3c.dom.Node.hasChildNodes方法的典型用法代码示例。如果您正苦于以下问题:Java Node.hasChildNodes方法的具体用法?Java Node.hasChildNodes怎么用?Java Node.hasChildNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mf.org.w3c.dom.Node
的用法示例。
在下文中一共展示了Node.hasChildNodes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: traverse
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
public static void traverse(Node node, int depth) {
indent(depth);
System.out.print("<"+node.getNodeName());
if (node.hasAttributes()) {
NamedNodeMap attrs = node.getAttributes();
for (int i=0; i<attrs.getLength(); i++) {
System.out.print(" "+((Attr)attrs.item(i)).getName()+"=\""+((Attr)attrs.item(i)).getValue()+"\"");
}
}
if (node.hasChildNodes()) {
System.out.println(">");
depth+=4;
for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
traverse(child, depth);
}
depth-=4;
indent(depth);
System.out.println("</"+node.getNodeName()+">");
}
else {
System.out.println("/>");
}
}
示例2: nextNode
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/** The method nextNode(Node, boolean) returns the next node
* from the actual DOM tree.
*
* The boolean visitChildren determines whether to visit the children.
* The result is the nextNode.
*/
Node nextNode(Node node, boolean visitChildren) {
if (node == null) return fRoot;
Node result;
// only check children if we visit children.
if (visitChildren) {
//if hasChildren, return 1st child.
if (node.hasChildNodes()) {
result = node.getFirstChild();
return result;
}
}
if (node == fRoot) { //if Root has no kids
return null;
}
// 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 != fRoot) {
result = parent.getNextSibling();
if (result != null) {
return result;
} else {
parent = parent.getParentNode();
}
} // while (parent != null && parent != fRoot) {
// end of list, return null
return null;
}
示例3: previousNode
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/** The method previousNode(Node) returns the previous node
* from the actual DOM tree.
*/
Node previousNode(Node node) {
Node result;
// if we're at the root, return null.
if (node == fRoot) return null;
// get sibling
result = node.getPreviousSibling();
if (result == null) {
//if 1st sibling, return parent
result = node.getParentNode();
return result;
}
// if sibling has children, keep getting last child of child.
if (result.hasChildNodes()
&& !(!fEntityReferenceExpansion
&& result != null
&& result.getNodeType() == Node.ENTITY_REFERENCE_NODE))
{
while (result.hasChildNodes()) {
result = result.getLastChild();
}
}
return result;
}
示例4: getFirstChild
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/** Internal function.
* Return the first child Node, from the input node
* after applying filter, whatToshow.
* The current node is not consulted or set.
*/
Node getFirstChild(Node node) {
if (node == null) return null;
if ( !fEntityReferenceExpansion
&& node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
return null;
Node newNode = node.getFirstChild();
if (newNode == null) return null;
int accept = acceptNode(newNode);
if (accept == NodeFilter.FILTER_ACCEPT)
return newNode;
else
if (accept == NodeFilter.FILTER_SKIP
&& newNode.hasChildNodes())
{
Node fChild = getFirstChild(newNode);
if (fChild == null) {
return getNextSibling(newNode, node);
}
return fChild;
}
else
//if (accept == NodeFilter.REJECT_NODE)
{
return getNextSibling(newNode, node);
}
}
示例5: getLastChild
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/** Internal function.
* Return the last child Node, from the input node
* after applying filter, whatToshow.
* The current node is not consulted or set.
*/
Node getLastChild(Node node) {
if (node == null) return null;
if ( !fEntityReferenceExpansion
&& node.getNodeType() == Node.ENTITY_REFERENCE_NODE)
return null;
Node newNode = node.getLastChild();
if (newNode == null) return null;
int accept = acceptNode(newNode);
if (accept == NodeFilter.FILTER_ACCEPT)
return newNode;
else
if (accept == NodeFilter.FILTER_SKIP
&& newNode.hasChildNodes())
{
Node lChild = getLastChild(newNode);
if (lChild == null) {
return getPreviousSibling(newNode, node);
}
return lChild;
}
else
//if (accept == NodeFilter.REJECT_NODE)
{
return getPreviousSibling(newNode, node);
}
}
示例6: nextMatchingElementAfter
import mf.org.w3c.dom.Node; //导入方法依赖的package包/类
/**
* Iterative tree-walker. When you have a Parent link, there's often no
* need to resort to recursion. NOTE THAT only Element nodes are matched
* since we're specifically supporting getElementsByTagName().
*/
protected Node nextMatchingElementAfter(Node current) {
Node next;
while (current != null) {
// Look down to first child.
if (current.hasChildNodes()) {
current = (current.getFirstChild());
}
// Look right to sibling (but not from root!)
else if (current != rootNode && null != (next = current.getNextSibling())) {
current = next;
}
// Look up and right (but not past root!)
else {
next = null;
for (; current != rootNode; // Stop when we return to starting point
current = current.getParentNode()) {
next = current.getNextSibling();
if (next != null)
break;
}
current = next;
}
// Have we found an Element with the right tagName?
// ("*" matches anything.)
if (current != rootNode && current != null
&& current.getNodeType() == Node.ELEMENT_NODE ) {
String name = ((ElementImpl) current).getAttribute( "name" );
if ( name.equals("*") || name.equals(tagName))
return current;
}
// Otherwise continue walking the tree
}
// Fell out of tree-walk; no more instances found
return null;
}