# load XML document from file
$xmlfile = "C:\Users\user1\Documents\123.xml"
[xml]$doc = Get-Content $xmlfile
# find element by tag name
$te = $doc.DocumentElement.SelectSingleNode("token")
# check if element exists
if (-not $te) {
# create the element if not exist
$te = $doc.CreateElement("token")
# append to DocumentELement
$doc.DocumentElement.AppendChild($te)
}
# set element value
$te.InnerText = "XXXXXXXX"
# save the document back to the file
$doc.Save($xmlfile)
No comments:
Post a Comment