binary.xml:<a>
<b>
<c>C</c>
<d>D</d>
</b>
<e>
<f>F</f>
<g>G</g>
</e>
</a>CountSubElts.java代码:import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;public class CountSubElts { // a variable for each component
protected DomSearch domSearch;
protected Dom2Sax dom2Sax;
protected CountSax countSax; /* the constructor instantiates the components and wires them together */
public CountSubElts() {
domSearch =
new DomSearch(); // obeys commands, reads files into DOM trees
dom2Sax = new Dom2Sax(); // takes us from DOM to SAX
domSearch.setSaxOutput(dom2Sax); // connect DomSearch to Dom2Sax
domSearch.initFromDict(new PropDict()); // start with defaults countSax = new CountSax(); // takes us from SAX to output
dom2Sax.setHandlerBase(countSax); // connect Dom2Sax to CountSax
} // pass all commands and definitions into the start of the pipe: public String doCommand(String cmd) {
return domSearch.doCommand(cmd);
}
public void setDef(String name, String val) { // calls setDef() of DomSeach that calls setDef() of its PropDict
// We use it below to set fileName in DomSearch
domSearch.setDef(name, val);
} // "traverse" uses the successor method of DomSearch
// to do a preorder examination of all subtrees of current node.
// We call writeNode() on each, sending the subtree to Dom2Sax
// which sends it to CountSax.
public void traverse() throws Exception {
Node startNode = domSearch.getNode();
Node currentNode = domSearch.successor(startNode);
while (startNode != currentNode) {
System.out.print(currentNode.getNodeName() + " ");
domSearch.writeNode(currentNode);
currentNode = domSearch.successor(currentNode);
}
} public static void main(String[] argv) throws Exception {
CountSubElts countSubElts = new CountSubElts(); // set fileName in DomSearch
countSubElts.setDef("fileName", argv[0]); // call doCommand() of DomSearch; the file gets parsed into DOM tree
String err = countSubElts.doCommand("initFile"); countSubElts.traverse();
}
}
<b>
<c>C</c>
<d>D</d>
</b>
<e>
<f>F</f>
<g>G</g>
</e>
</a>CountSubElts.java代码:import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;public class CountSubElts { // a variable for each component
protected DomSearch domSearch;
protected Dom2Sax dom2Sax;
protected CountSax countSax; /* the constructor instantiates the components and wires them together */
public CountSubElts() {
domSearch =
new DomSearch(); // obeys commands, reads files into DOM trees
dom2Sax = new Dom2Sax(); // takes us from DOM to SAX
domSearch.setSaxOutput(dom2Sax); // connect DomSearch to Dom2Sax
domSearch.initFromDict(new PropDict()); // start with defaults countSax = new CountSax(); // takes us from SAX to output
dom2Sax.setHandlerBase(countSax); // connect Dom2Sax to CountSax
} // pass all commands and definitions into the start of the pipe: public String doCommand(String cmd) {
return domSearch.doCommand(cmd);
}
public void setDef(String name, String val) { // calls setDef() of DomSeach that calls setDef() of its PropDict
// We use it below to set fileName in DomSearch
domSearch.setDef(name, val);
} // "traverse" uses the successor method of DomSearch
// to do a preorder examination of all subtrees of current node.
// We call writeNode() on each, sending the subtree to Dom2Sax
// which sends it to CountSax.
public void traverse() throws Exception {
Node startNode = domSearch.getNode();
Node currentNode = domSearch.successor(startNode);
while (startNode != currentNode) {
System.out.print(currentNode.getNodeName() + " ");
domSearch.writeNode(currentNode);
currentNode = domSearch.successor(currentNode);
}
} public static void main(String[] argv) throws Exception {
CountSubElts countSubElts = new CountSubElts(); // set fileName in DomSearch
countSubElts.setDef("fileName", argv[0]); // call doCommand() of DomSearch; the file gets parsed into DOM tree
String err = countSubElts.doCommand("initFile"); countSubElts.traverse();
}
}
解决方案 »
- 在某个时间点出发程序中的某个方法
- weblogic 部署问题
- 自动执行
- 请高手来帮我看一下,谢谢!
- 牛人门,怎么做JDBC的缓存?
- java做webservice服务端,.net做客户端webservice的调用问题??? up给分
- 明明是save,提示的则为update???
- 我学JSP也有一段时间了..........我应该买那本书来系统学习JAVA??????
- 有谁能介绍一本介绍搜索引擎基本原理书啊?(最好有用java实现的例子)非常感谢!
- 急呀,哪儿有JBIULDER的电子中文入门书籍下载!!
- 对J2EE的感受!
- 请问到哪能找到可以在JBuiler7/8中进行曲线绘制的组件或工具(类似于TChart)?
SAXException
{ String s = new String(ch, start, length);
if(!s.startsWith("\n") && !"".equals(s.trim()))
{
System.out.println(s);//s is what you needed
} }