批处理/ powershell

时间:2017-04-18 10:54:28

标签: powershell batch-file

我有两个文件,第一个包含名称列表:

"Dagger Alley 1"
"Steel Home"
"Iron Alley 1"
"Iron Alley 2"
"Swamp Watch"
"Salvation Street 2"
"Salvation Street 3"
"Silver Street 3"
"Golden Axe Guildhall"

第二个包含另一个列表:

<house name="" houseid="2" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="93" />
<house name="" houseid="4" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="68" />
<house name="" houseid="5" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="94" />
<house name="" houseid="6" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="133" />
<house name="" houseid="7" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="73" />
<house name="" houseid="8" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="101" />

如何将文件1中的条目插入文件2中的name字段,如下所示:

<house name="Dagger Alley 1" houseid="2" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="93" />

1 个答案:

答案 0 :(得分:0)

以下应该让你开始

$housenames = @("Dagger Alley 1"
"Steel Home"
"Iron Alley 1"
"Iron Alley 2"
"Swamp Watch"
"Salvation Street 2"
)

$xmlTemplate = @(
'<house name="" houseid="2" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="93" />'
'<house name="" houseid="4" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="68" />'
'<house name="" houseid="5" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="94" />'
'<house name="" houseid="6" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="133" />'
'<house name="" houseid="7" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="73" />'
'<house name="" houseid="8" entryx="0" entryy="0" entryz="0" rent="0" townid="0" size="101" />'
)

for ($i=0;$i -lt $housenames.Count; $i++) {    
    $xmlTemplate[$i] -replace '<house name=""', "<house name=""$($housenames[$i])"""
}