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)