用Dom4J解析带命名空间的XML文件
Dom4J是一个开源的优秀的XML解析API,现在越来越多的项目中开始采用这种解析方式,其中包含了著名的Hibernate。这里我们使用Dom4J解析一个带命名空间的CXF的Spring配置文件。先导入dom4j-1.6.1.jar
spring 配置文件 applicationContext-cxf.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd"
default-autowire="byName" default-lazy-init="true">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<bean id="jaxWsServiceFactoryBean" class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean" scope="prototype">
<property name="wrapped" value="true"/>
<property name="dataBinding" ref="aegisBean"/>
<property name="serviceConfigurations">
<list>
<bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration"/>
<bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration"/>
<bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration"/>
</list>
</property>
</bean>
<bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding"/>
<jaxws:endpoint id="WSpersonService" implementor="#personService" address="/PersonService">
<jaxws:serviceFactory>
相关文档:
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Iterator;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class ReadSetting {
......
一.生成document对象。
import org.jdom.*;
import org.jdom.input.SAXBuilder;
public class ReportDocUtil {
public ReportDocUtil() {
}
/**
* <p>Description:covert xml file to Document</p>
* @param url 格式xml文件的存放的相对路径
& ......
XmlDocument xmldoc = new XmlDocument();//创建xml文档对象
XmlNode root;//根节点
xmldoc.Load(Server.MapPath("address.xml"));//加载xml文档
root = xmldoc.DocumentEle ......
//打开某文件(假设web.config在根目录中)
string filename=Server.MapPath("/") + @"WebApplication1\web.config";
XmlDocument xmldoc= new XmlDocument();
xmldoc.Load(filename);
//得到顶层节点列表
......
package cn.com.xml.vo;
public class RosterVo {
private String id; //学号
private String name; //学生姓名
private String age; //年龄
private String skill; //科目 ......