前端之家收集整理的这篇文章主要介绍了
使用PowerShell将xml从UTF-16转换为UTF-8,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这可能不是最佳的,但它的作品。只需加载xml并将其推回到
文件。 xml
标题丢失了,所以必须重新
添加。
$files = get-ChildItem "*.xml"
foreach ( $file in $files )
{
[System.Xml.XmlDocument]$doc = new-object System.Xml.XmlDocument;
$doc.set_PreserveWhiteSpace( $true );
$doc.Load( $file );
$root = $doc.get_DocumentElement();
$xml = $root.get_outerXml();
$xml = '<?xml version="1.0" encoding="utf-8"?>' + $xml
$newFile = $file.Name + ".new"
Set-Content -Encoding UTF8 $newFile $xml;
}