易截截图软件、单文件、免安装、纯绿色、仅160KB

用Dom4j来解析xml文件

package com.pk.xml;
import java.io.File;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class Dom4j {
public static void main(String[] args) {
try {
//获得SAX解析器
SAXReader reader = new SAXReader();

//解析文件
File file = new File("D:\\项目\\me\\mobilelist.xml");
Document document = reader.read(file);
//获取跟节点
Element root = document.getRootElement();
//获得子节点列表
for(int i = 0 ; i<root.nodeCount();i++){
//取得某一个子节点
Element book = (Element) root.node(i);
//取得属性值
String type = book.attributeValue("type");
System.out.print(type+"\t");

String wap2 = book.node(0).getText();
String wedint = book.node(1).getText();
System.out.print(wap2+"\t");
System.out.println(wedint+"\t");
}
} catch (Exception e) {
e.printStackTrace();
}

}
}


相关文档:

XML解析方法讲解

XML现在已经成为一种通用的数据交换格式,它的平台无关性,语言无关性,系统无关性,给数据集成与交互带来了极大的方便。对于XML本身的语法知识与技术细节,需要阅读相关的技术文献,这里面包括的内容有DOM(Document Object Model),DTD(Document Type Definition),SAX(Simple API for XML),XSD(Xml Schema Definition),XSLT(Exten ......

用jdom实现将数据库资料生成xml文件

今天的项目模块中用到根据数据库里的资料生成xml文件,主要步骤如下:
(1) 连接数据库,取出数据;
(2) 创建结点,添加子项;
(3) 写入文件“test.xml”中;
具体代码如下:
import java.io.FileOutputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Result ......

XML第二课

wsdl.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<definitions  name="MobilePhoneService"
     targetNamespace="www.mobilephoneservice.com/MobilePhoneService-interface"
     xmlns="http://schemas.xmlsoap.org/wsdl/"
     ......

XML的创建

       声明
        /// <summary>
        /// XML文档
        /// </summary>
        XmlDocument xmldoc;
 &n ......

解析xml文件的几种常见的方法

xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<mobile-list>
<mobile type="Nokia2652">
<wap2>false</wap2>
<width>115</width>
</mobile>
<mobile type="Nokia2650">
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号