IIS配置文件解析 读取值问题

rgone 发布于 2013/04/15 16:41
阅读 125
收藏 0
IIS

想把iis的配置文件解析一下,请帮忙说明一下思路,谢谢!


<?xml version="1.0" encoding="UTF-8"?>
<sites>
<site name="Default Web Site" id="1" serverAutoStart="true">
	<application path="/">
		<virtualDirectory path="/" physicalPath="%SystemDrive%\inetpub\wwwroot" />
	</application>
	<application path="/MSMQ" applicationPool="DefaultAppPool">
		<virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\msmq" />
	</application>
	<bindings>
		<binding protocol="http" bindingInformation="*:80:" />
		<binding protocol="net.tcp" bindingInformation="808:*" />
		<binding protocol="net.pipe" bindingInformation="*" />
		<binding protocol="net.msmq" bindingInformation="localhost" />
		<binding protocol="msmq.formatname" bindingInformation="localhost" />
	</bindings>
	<logFile directory="E:\Weblog\W3C1_Default Web Site" period="Hourly" localTimeRollover="true" />
</site>
<site name="spcartservice.taobao.com" id="2">
	<application path="/" applicationPool="spcartservice.taobao.com">
		<virtualDirectory path="/" physicalPath="E:\spcartservice.taobao.com" />
	</application>
	<bindings>
		<binding protocol="http" bindingInformation="*:80:spcartservice.taobao.com" />
	</bindings>
	<logFile directory="E:\Weblog\W3C2_spcartservice.taobao.com" period="Hourly" localTimeRollover="true" />
</site>
</sites>
想得到的数据是:


sitename physicalPath
applicationPool
logFile directory

NodeList nodelist = document.getElementsByTagName("site");
for(int i=0;i<nodelist.getLength();i++){
	node = nodelist.item(i);
	NamedNodeMap nodemap = node.getAttributes();
	for(int k=0;k<nodemap.getLength();k++){
		nodes = nodemap.item(k);
		if(nodes.getNodeName()=="name"){
		System.out.println("属性:"+nodes.getNodeName()+"=" + nodes.getTextContent());
		System.out.println("----------------------");
		}
	}
}

加载中
返回顶部
顶部