一个用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");
相关文档:
在此先感谢http://blog.chinaunix.net/u3/111961/showart_2187819.html
。这是篇极好的文章。
在上次学习中,我们写了client小例子,非常简单,而且通过dbus-binding-tool生成的头文件,非常规范。相比执行,server稍微复杂些,仍然使用上次的xml文件,但是去掉annotation,更为本原一些。文件wei.xml如下:
& ......
//******************** 头文件 Markup.h *******************
// Markup.h: interface for the CMarkup class.
//
// Markup Release 11.2
// Copyright (C) 2009 First Objective Software, Inc. All rights reserved
// Go to www.firstobject.com for the latest CMarkup and EDOM documentation
// ......
对于带有表空间xmlns的xml文件的解析,用正常解析文件的方法总是失效,不起作用,无法获得元素。
下面给出两种方法解析此类文件:
1.按正常解析xml文件的方法,需要注意几点:
获取元素Element,不可使用函数:document.selectNodes("//region");
只可以先取到根元素,一级一级往下取,eg:
Element root = document.g ......
FusionCharts 的 XML标签属性有一下四种数据类型
* Boolean - 布尔类型,只能为1或者0。例如:<graph showNames=’1′ >
* Number - 数字类型,只能为数字。例如:<graph yAxisMaxValue=’200′ >
* String - 字符串类型,只能为字符串。例如: <graph caption=’My Chart&r ......
在使用Goddady主机使用
Google XML
Sitemaps插件的时候,总提示无权限,而实际上我是了权限的,把插件下载到本地,也是可以正常生成sitemap的,怎么办?自然不能难倒咱
Iter。
检索多方检查,发现在服务器上,检查路径一项为sitemap.xml,而在本地,检查路径
为d:\workstation\site\iove.net\sitemap.xml,也就是说 ......