1.直接加入xml結構
加入<title>是為了后續能直接添加其他node,否則,后續操作可能無法AppendChild
$xml = "<?xml version='1.0' encoding='UTF-8'?><case><title>please check each point</title></case>"$xml|Out-File $xmlFile
2.讀取xml文件
加入 -Encoding UTF8 中文不亂碼
$xmldata =[XML](Get-Content $xmlFile -Encoding UTF8)
$pointCount=$xmldata.case.SelectNodes("point").Count+1
3.字標簽添加
$innerXml = "
<number>$pointCount</number>
<name>$nameValue</name>
<result>$resultValue</result>
<filePath>$filePathValue</filePath>
<time>$timeValue</time>
<mark>$markValue</mark>
"$newPoint = $xmldata.CreateElement("point")
$newPoint.set_InnerXML($innerXml)
$xmldata.case.AppendChild($newPoint)
?
4.保存
$xmldata.Save($xmlFile)
?