过去几天我一直在尝试创建一个 Powershell 脚本,该脚本将创建一个 XML 文件,其中包含 2 个字段来表示时间。问题是创建的 XML 是CR LF with UTF-8 BOM
我需要的LF with UTF-8
。
编辑- 遵循“LotPings”的建议,添加代码确实将 XML 更改为 Unix(FL),但它仍然在 UTF8-BOM 上,但它给我带来了问题。如何将其从 UTF8-BOM 更改为 UTF8?
我从未处理过 Powershell,也不知道如何实现这一点。
# Set The Formatting
$xmlsettings = New-Object System.Xml.XmlWriterSettings
$xmlsettings.Indent = $true
$xmlsettings.IndentChars = " "
$hour = (Get-Date).hour
$day = (Get-Date).dayofweek
# Checking If Its Too Late
If ($day -eq "Saturday" -and $hour -lt "8")
{
$hour = "00"
}
else
{
if ($day -ne "Saturday" -and $hour -lt "7")
{
$hour = "00"
}
}
# Set the File Name Create The Document
$XmlWriter = [System.XML.XmlWriter]::Create("S:\NowPlaying\Ch0-News13.xml", $xmlsettings)
# Start the Root Element
$xmlWriter.WriteStartElement("track")
$xmlWriter.WriteElementString("name",$hour.ToString()+":00" + "News Flash of")
$xmlWriter.WriteElementString("artist","News Channel")
$xmlWriter.WriteEndElement() # <-- End <Track>
# End, Finalize and close the XML Document
$xmlWriter.WriteEndDocument()
$xmlWriter.Flush()
$xmlWriter.Close()