【已解决】怎么修改XML文件内容
本帖最后由 3131210 于 2017-5-23 15:31 编辑有个xml文件想正则搜索 ':\\.*\\' 自动修改 内容为au3所在当前目录 附上2段可以用的代码
直接正则暴力修改 有没有其他办法 比如读取xml字段编辑
代码1$open = FileOpen("config.xml", 0)
$read = FileRead($open)
FileClose($open)
Local $DZ = StringRegExpReplace(@ScriptDir, '\\', '\\\\')
Local $Test = StringRegExpReplace($read, ':\\.*\\', $DZ & "\\")
$open = FileOpen("config.xml", 2)
FileWrite($open, $Test)
FileClose($open)
代码2#Include <File.au3>
$IniFile = "config.xml"
$Lines = _FileCountLines($IniFile)
Local $DZ = StringRegExpReplace(@ScriptDir, '\\', '\\\\')
For $i=1 To $Lines
$ReadFile=FileReadLine($IniFile,$i)
If stringinstr($ReadFile,"<location>") Then
Local $Test = StringRegExpReplace($ReadFile, '<location>.*\\', "<location>" & $DZ & "\\")
FileWriteLine("new.txt", $Test)
ElseIf stringinstr($ReadFile,"<BackupPath>") Then
Local $Test = StringRegExpReplace($ReadFile, '<BackupPath>.*\\', "<BackupPath>" & $DZ & "\\")
FileWriteLine("new.txt", $Test)
Else
FileWriteLine("new.txt", $ReadFile)
EndIf
NEXT
FileMove("new.txt", "config.xml", 1)xml的内容<?xml version="1.0" encoding="utf-8"?>
<xml>
<pexconfig>
<PhraseFile>
<Data>
<phrases>
<min_ver>10.0.34</min_ver>
<version>4.0.21</version>
<autolearn>
<description>Word 自动更正</description>
<location>D:\PhraseExpress\autocorrect.pxp</location>
<project_name>False</project_name>
</autolearn>
<clipboard>
<description>剪贴板缓存</description>
<location>D:\PhraseExpress\clipboard.pxp</location>
<cacheloaded>False</cacheloaded>
</clipboard>
<file>
<description>新建本地文件</description>
<location>D:\PhraseExpress\phrases.pxp</location>
<cacheloaded>False</cacheloaded>
</file>
</phrases>
</Data>
<NP/>
<DoSyncFiles>-1</DoSyncFiles>
<PhrasesTouched>0</PhrasesTouched>
<ServerSwitched>0</ServerSwitched>
<DBT/>
<DBTS/>
<BackupCount>99</BackupCount>
<BackupPath>D:\PhraseExpress\</BackupPath>
<CacheSQLData>0</CacheSQLData>
<LastSaveTarget/>
<SaveHistoryPaths/>
</PhraseFile>
</pexconfig>
</xml>
看看{:face (303):} 可以把你的正则翻译一下么? 回复 1# 3131210
学习学习 回复 1# 3131210
学习学习
页:
[1]