zhusheng8701 发表于 2010-3-14 15:00:06

【求助】autoit读xml文件,谢谢

分析xml文件,读取其中的值存为记事本文件<IIsWebServer      Location ="/LM/W3SVC/246"
                ServerBindings="127.0.0.1:80:www.baidu.com
                        127.0.0.1:80:baidu.com
                        127.0.0.1:80:hi.baidu.com"
                ServerComment="baidu"
      >
</IIsWebServer>
<IIsWebServer        Location ="/LM/W3SVC/23"
                AccessFlags="AccessRead | AccessScript"
                AnonymousUserName="hi"
                AnonymousUserPass="4963446260000000160000004000000097939c00ac4315bbddccd975981ee6547fb3cc9f7ab06c0b5a9aa3b59a7a6b39d591b081c64ee3afd06a41d0b85b9e753692174c9a860444e4193ec301ed51b4d57a54bb114ef1bec5f220e5bd2fd908f04c6685a9116b82"
                AppPoolId="apppool025001"
                AspEnableParentPaths="TRUE"
                ConnectionTimeout="90"
                DefaultDoc="index.php,default.php,index.asp,default.asp,index.htm,index.html,default.htm,default.html"
                DirBrowseFlags="DirBrowseShowDate | DirBrowseShowTime | DirBrowseShowSize | DirBrowseShowExtension | EnableDefaultDoc"
                LogExtFileFlags="LogExtFileTime | LogExtFileClientIp | LogExtFileMethod | LogExtFileUriStem | LogExtFileHttpStatus | LogExtFileBytesSent | LogExtFileBytesRecv"
                LogFileDirectory="d:\wwwroot\hi\logfiles"
                LogType="1"
                MaxBandwidth="262144"
                MaxConnections="140"
                ServerBindings="127.0.0.1:80:www.baidu.com
                        127.0.0.1:80:hi.baidu.com"
                ServerComment="hi"
        >
</IIsWebServer>
<IIsWebVirtualDir        Location ="/LM/W3SVC/23/ROOT"
                AccessFlags="AccessRead | AccessScript"
                AppFriendlyName="app_ahfox"
                AppIsolated="2"
                AppPoolId="apppool025001"
                AppRoot="/LM/w3svc/23/ROOT"
                Path="d:\wwwroot\hi\wwwroot"
                ScriptMaps=".mp3,C:\dll\no.dll,5
                        .zip,C:\dll\no.dll,5
                        .rar,C:\dll\no.dll,5
                        .wav,C:\dll\no.dll,5
                        .tar,C:\dll\no.dll,5
                        .php,C:\PHP\php5isapi.dll,5,GET,HEAD,POST,TRACE
                        .php3,C:\PHP\php5isapi.dll,5,GET,HEAD,POST,TRACE
                        .shtm,C:\WINDOWS\system32\inetsrv\ssinc.dll,1,GET,POST
                        .shtml,C:\WINDOWS\system32\inetsrv\ssinc.dll,1,GET,POST
                        .asp,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE
                        .asa,C:\WINDOWS\system32\inetsrv\asp.dll,5,GET,HEAD,POST,TRACE"
        >
</IIsWebVirtualDir>
<IIsWebDirectory        Location ="/LM/W3SVC/23/ROOT/aspnet_client"
                AccessFlags="AccessRead"
                DirBrowseFlags="0"
        >
</IIsWebDirectory>读 ServerBindings 值 和 ServerComment值 。
保存为记事本文件,格式如下:

baidu.com
hi.baidu.com
www.baidu.com


www.baidu.com
hi.baidu.com
google.com

zhusheng8701 发表于 2010-3-14 15:01:15

谢谢。。。求助啦,,,

rikthhpgf2005 发表于 2010-3-14 17:00:10

!!学习中..顶下:face (23):

zmj2008 发表于 2010-3-14 22:18:24

!!学习中..顶下

devilma 发表于 2010-3-14 22:20:14

顶起,等高人。。。

sanmoking 发表于 2010-3-14 23:31:14

没看懂。。

sanmoking 发表于 2010-3-14 23:32:17

又看了一遍,看懂了。。

sanmoking 发表于 2010-3-14 23:42:06

太晚了,没精力写代码了,给楼主一个思路,
1、把整个文件中【<IIsWebServer】和【</IIsWebServer>】之间的字符读取出来,可利用这个帖子的原理【传送门】
2、从上面的到的结果中再,分别获取指定项的值就很容易了。。
【另一个传送门,没有用正则的方法】

afan 发表于 2010-3-15 00:38:35

$str = FileRead('xml.xml')

$a = test($str, 'baidu')
$a &= test($str, 'hi')
FileWrite('xml.txt', $a)
ShellExecute('xml.txt')

Func test($str, $gjz)
        Local $out = '[' & $gjz & ']' & @CRLF
        $sRR = StringRegExpReplace($str, '(?s)(?i).+ServerBindings=\"(.+)?ServerComment=\"' & $gjz & '\".+', '$1')
        If @extended = 0 Then Return $out & @CRLF
        $sR = StringRegExp($sRR, '([^:]+?)\"?\r?\n', 3)
        If @error Then Return $out & @CRLF
        For $i = 0 To UBound($sR) - 1
                $out &= $sR[$i] & @CRLF
        Next
        Return $out & @CRLF
EndFunc   ;==>test
页: [1]
查看完整版本: 【求助】autoit读xml文件,谢谢