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

xml解析


在java应用开发中我们和xml打交道得机会太平凡了,一般情况下我看会用JDOM或是DOM4j来解析我们得XML文件,下面是一个Dom4j解析xml文件得例子,其中包括了对xml文件得取值、赋值、提取节点、节点得遍历等。
SAXReader reader =
new
SAXReader();   
Document doc = reader.read(...);   
List childNodes = doc.selectNodes("//Config/Child/ChildNode"
);   
for
(Object obj:childNodes) {   
Node childNode = (Node)obj;   
  
String name = childNode.valueOf("@name"
);   
String text = childNode.getText();   
}   
  
  
  
一.Document对象相关  
  
1
.读取XML文件,获得document对象.  
              SAXReader reader = new
SAXReader();  
              Document    document = reader.read(new
File(
"input.xml"
));  
  
2
.解析XML形式的文本,得到document对象.  
              String text = "<members></members>"
;  
              Document document = DocumentHelper.parseText(text);  
3
.主动创建document对象.  
              Document document = DocumentHelper.createDocument();  
              Element root = document.addElement("members"
);
// 创建根节点
  
二.节点相关  
  
1
.获取文档的根节点.  
Element rootElm = document.getRootElement();  
2
.取得某节点的单个子节点.  


相关文档:

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 ......

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

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

LINQ TO XML Common Class

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

用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 = n ......

php之XML转数组函数

<?
/**
* xml2array() will convert the given XML text to an array in the XML structure.
* Link: http://www.bin-co.com/php/scripts/xml2array/
* Arguments : $contents - The XML text
* $get_attributes - 1 or 0. If this is 1 the function will get the attributes as well as the ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号