易截截图软件、单文件、免安装、纯绿色、仅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文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</booksto ......

xml/properties文件的相互保存转化

/*
练习使用java.util.properties类包来操作propertes及XML文件,通过store方法的调用可实现xml/properties文件的相互保存转化
*/
import java.util.*;
import java.io.*;
public class TestPropertes
{
public static void main(String[] args) {
   Properties pp = new Properties();
   Fi ......

LINQ TO XML Common Class

个人收集、整理了一些LINQ TO XML的基本方法,希望各位大虾多多指导:
 /// <summary>
///Xml节点属性
/// </summary>
public class XmlAttribute
{
 public XmlAttribute()
 {
  
 }
    public XmlAttribute(string _key,object _value)
 &nbs ......

用jdom来解析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号