<?xml version="1.0" encoding="utf-8"?>
<PDA >
<title title="PDA"></title>
<formid formid="0"></formid>
<first>
<title title="信息采集系统"></title>
<formid formid="01"></formid>
<tableName tableName="商品"></tableName>
<id id="1"></id>
<type type="name1"></type>
<name name="数据采集"></name>
</first>
<seconed>
<title title="用户信息"></title>
<formid formid="0101"></formid>
<tableName tableName="product"></tableName>
<id id="101"></id>
<type type="button1"></type>
<name name="取消"></name>
<fieldname fieldname=""></fieldname>
</seconed>
<seconed>
<title title="帐号管理"></title>
<formid formid="0102"></formid>
<tableName tableName="product"></tableName>
<id id="102"></id>
<type type="buttonno"></type>
<name name="确定"></name>
<fieldname fieldname=""></fieldname>
</seconed>
<first>
<title title="发布"></title>
<formid formid="02"></formid>
<tableName tableName=""></tableName>
<id id="2"></id>
<type type=""></type>
<name name="发布"></name>
</first>
<first>
<title title="二维码"></title>
<formid formid="03"></formid>
<tableName tableName=""></tableName>
<id id="3"></id>
<type type=""></type>
<name name="用户管理"></name>
</first>
<first>
<title title="04"></title>
<formid formid="04"></formid>
<tableName tableName=""></tableName>
<id id="4"></id>
<type type=""></type>
<name name="图片采集"></name>
</first>
</PDA>
<PDA >
<title title="PDA"></title>
<formid formid="0"></formid>
<first>
<title title="信息采集系统"></title>
<formid formid="01"></formid>
<tableName tableName="商品"></tableName>
<id id="1"></id>
<type type="name1"></type>
<name name="数据采集"></name>
</first>
<seconed>
<title title="用户信息"></title>
<formid formid="0101"></formid>
<tableName tableName="product"></tableName>
<id id="101"></id>
<type type="button1"></type>
<name name="取消"></name>
<fieldname fieldname=""></fieldname>
</seconed>
<seconed>
<title title="帐号管理"></title>
<formid formid="0102"></formid>
<tableName tableName="product"></tableName>
<id id="102"></id>
<type type="buttonno"></type>
<name name="确定"></name>
<fieldname fieldname=""></fieldname>
</seconed>
<first>
<title title="发布"></title>
<formid formid="02"></formid>
<tableName tableName=""></tableName>
<id id="2"></id>
<type type=""></type>
<name name="发布"></name>
</first>
<first>
<title title="二维码"></title>
<formid formid="03"></formid>
<tableName tableName=""></tableName>
<id id="3"></id>
<type type=""></type>
<name name="用户管理"></name>
</first>
<first>
<title title="04"></title>
<formid formid="04"></formid>
<tableName tableName=""></tableName>
<id id="4"></id>
<type type=""></type>
<name name="图片采集"></name>
</first>
</PDA>
解决方案 »
- 关于GUI的两个问题!
- 为什么读不了下一行数据呢?
- 输入流能指定写入的文件格式吗?
- 求一个把把server端的resultSet传到client端显示到JTable的例子。
- 为什么这段代码打印的是象扑克牌一样的四种花色
- 搜寻搜索引擎接口
- applet连接数据库的问题
- 停在断点后AppletViewer不能再继续了……
- 我写的像数据库提交图片的程序,但是不成功,强各位大虾帮忙分析一下,谢谢!!
- Visual Age for Java如何可以连接到Domino数据库中,从数据库的某一篇文档中读出一此信息处理后再写入文档,采用DIIOP,远程连接方式
- java项目打包运行保存成jar文件,疑难问题求解!
- 关于Java调用dll的一个问题. 在我电脑上可以运行,在其他电脑上就不行了
package com.ruihui.test;import java.io.FileInputStream;
import java.io.IOException;import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;public class XmlParseTest {
public static void main(String[] args) throws SAXException, IOException, ParserConfigurationException {
FileInputStream in=new FileInputStream("d:/test.xml"); SAXParserFactory spf=SAXParserFactory.newInstance();
SAXParser parser=spf.newSAXParser();
parser.parse(in, new MyHandler());
in.close();
}
}class MyHandler extends DefaultHandler{
private int space=0;
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
for(int i=0;i<space;i++){
System.out.print('\t');
}
System.out.println(qName+' '+attributes.getValue("title"));
space ++;
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
space --;
}
}
import java.io.FileReader;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;public class Example {
public static void main(final String[] args) {
try {
XPathFactory factory = XPathFactory.newInstance();
XPath xpath = factory.newXPath();
XPathExpression xpe = xpath.compile("//title/@title");
NodeList nodes = (NodeList)xpe.evaluate(new InputSource(new FileReader("pda.xml")),XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println(nodes.item(i).getTextContent());
}
} catch (XPathExpressionException|FileNotFoundException e) {
System.err.println(e.getMessage());
}
}
}
结果
$java Example
PDA
信息采集系统
用户信息
帐号管理
发布
二维码
04
$java -version
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)