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

一个用Dom4j解析xml的例子

一、测试用的em.xml
<?xml version="1.0" encoding="GB2312"?>
 <EW cmd="login" mod="Login" version="6.0">
   <Source uns="" type="user"/>
   <Username>zhangzhiyun@hp</Username>
   <Password>111111</Password>
  <Version>6.01.06.00</Version>
</EW>
二、Dom4jTest.java
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import org.apache.log4j.Logger;
import org.dom4j.Attribute;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
/**
* @author julysea
*
* 一个用Dom4j解析xml的例子
*
*/
public class Dom4jTest {
private static final Logger logger = Logger.getLogger(Dom4jTest.class);
public static void main(String[] args) throws IOException,
DocumentException {
BufferedReader reader=new BufferedReader(new FileReader("ew.xml"));
String tempStr;
String ewXml="";
while((tempStr=reader.readLine())!=null) {
ewXml=ewXml+tempStr;
logger.debug(tempStr);
}
Element root = null;
root = DocumentHelper.parseText(ewXml).getRootElement();
Attribute rootCmd=root.attribute("cmd");
Attribute rootVersion=root.attribute("version");
logger.debug("rootNmae = "+root.getName());
logger.debug("EW'cmd = "+rootCmd.getValue());
logger.debug("EW'version = "+rootVersion.getValue());
Element usrName=root.element("Username");
logger.debug("EW.Username value = "+usrName.getTextTrim());
Element source=root.element("Source");
Attribute sourceUns=source.attribute("uns");
logger.debug("EW.Source'uns="+sourceUns.getValue());
Attribute sourceType=source.attribute("type");


相关文档:

Parsing XML from the Net Using the SAXParser


Parsing XML from the Net - Using the SAXParser
http://www.anddev.org/parsing_xml_from_the_net_-_using_the_saxparser-t353.html
What you learn:
You will learn how to properly parse XML
(here: from the net
) using a SAXParser
.
What it will look like:
Description:
0.)
In this tutorial we ......

Expat XML解析器的介绍

互联网发展得很快,都是源自于使用了超文本的表达方式。比如你查看一篇文章,看到不懂的关键字,就可以通过链接去查看它的内容,看完之后再回来接着看原来的东西,这样比较适合学习的方式。使用HTML标记的文本,是结构化储存的,这样的表达方式才可以实现超级连接。由于HTML具有超强的表达能力,也就在互联网上生存下来,那 ......

xml的序列化和反序列化

XML序列化与反序列化 整理文档
XML序列化与反序列化
    // OBJECT -> XML
    public static void SaveXml(string filePath, object obj) { SaveXml(filePath, obj, obj.GetType()); }
    public static void SaveXml(string filePath, object obj, System.Type ty ......

对于带有表空间xmlns的xml文件的解析

对于带有表空间xmlns的xml文件的解析,用正常解析文件的方法总是失效,不起作用,无法获得元素。
下面给出两种方法解析此类文件:
1.按正常解析xml文件的方法,需要注意几点:
获取元素Element,不可使用函数:document.selectNodes("//region");
只可以先取到根元素,一级一级往下取,eg:
Element root = document.g ......

Google XML Sitemaps总是提示无权限?


在使用Goddady主机使用
Google XML
Sitemaps插件的时候,总提示无权限,而实际上我是了权限的,把插件下载到本地,也是可以正常生成sitemap的,怎么办?自然不能难倒咱
Iter。
检索多方检查,发现在服务器上,检查路径一项为sitemap.xml,而在本地,检查路径
为d:\workstation\site\iove.net\sitemap.xml,也就是说 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号