【发布时间】:2019-07-15 12:07:50
【问题描述】:
过去几天我一直在尝试创建一个 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()
【问题讨论】:
标签: xml powershell lf