⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 domwalker.java

📁 开源框架
💻 JAVA
字号:
/**
 */

package org.infohazard.domify.test;

import org.w3c.dom.*;
import java.io.*;

/**
 */
public class DOMWalker
{
	PrintStream out;
	int depth = 0;

	public DOMWalker(PrintStream out)
	{
		this.out = out;
	}

	public void walk(Node node)
	{
		String nodeName;
		try { nodeName = node.getNodeName(); }
		catch (UnsupportedOperationException ex) { nodeName = "Unsupported"; }

		String nodeValue;
		try { nodeValue = node.getNodeValue(); }
		catch (UnsupportedOperationException ex) { nodeValue = "Unsupported"; }

		println("node type:   " + node.getNodeType());
		println("node name:   " + nodeName);
		println("node value:  " + nodeValue);

		depth++;

		NodeList children = node.getChildNodes();
		for (int i=0; i<children.getLength(); i++)
		{
			Node child = children.item(i);
			this.walk(child);
		}

		depth--;
	}

	protected void println(String str)
	{
		for (int i=0; i<depth; i++)
			out.print("  ");

		out.println(str);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -