我剛開始學習 PowerShell(字面意思是 - 僅僅一周時間,完全來自在線教程和材料 :))所以不要對我苛刻)
我會很感激幫助以及如何做到這一點,因為我被困在這一點上。所以我有這個模板檔案,我創建了 10 個副本,但我不知道如何更改兩個 td 標記值“。” 每個副本中標題和藝術家的名稱不同。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td>.</td>
<td>.</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
這是我走了多遠,但我將不勝感激一些幫助/建議/解釋正確的進一步步驟..
[xml]$File= get-content "\MyXMLFile.xml"
1..10 |% { Copy-Item "\MyXMLFile.xml" "MyXMLFile$_.xml"}
$copiedFiles =@(Get-ChildItem -Path "XmlFileFolder" | % Name)
$exampleNode = $File.SelectNodes("//td[1]")
$TitleNodeArray = @('aa', 'bb', 'cc', etc..) #but I have no idea how to go on from there ..
uj5u.com熱心網友回復:
嘗試這個。
using assembly System
using assembly System.Linq
using assembly System.Xml.Linq
$inputFilename = "c:\temp\test.xml"
$xDoc = [System.Xml.Linq.XDocument]::Load($inputFilename)
$tds = $xDoc.Descendants("td").Foreach([System.Xml.Linq.XElement])
$td0 = $tds[0]
$td1 = $tds[1]
Write-Host $xDoc
$newWords1 = @("abc1","def1","ghi1","jkl1","mno1","pqr1","stu1","vwx1","yz11","2341")
$newWords2 = @("abc2","def2","ghi2","jkl2","mno2","pqr2","stu2","vwx2","yz12","2342")
for($i = 0; $i -lt 10; $i )
{
Write-Host $i $newWords1[$i]
$td0.SetValue($newWords1[$i])
$td1.SetValue($newWords2[$i])
$xDoc.Save("c:\temp\testoutput" $i ".xml")
}
uj5u.com熱心網友回復:
嗯,我不太使用 xml,但我知道使用Select-Xml.
(Select-Xml -Xml $File -XPath '//tr/td')[1].Node."#text" = 'title'
[1]索引節點在哪里,并且#text是值/文本本身。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/523430.html
標籤:数组xml电源外壳
上一篇:讀取檔案、修改內容和寫入新檔案
下一篇:在其他兩個元素之間定位布局
