【发布时间】:2019-07-19 01:00:46
【问题描述】:
我正在尝试将 XML 转换为 UTF-8 并为转换后的文件创建一个新目录。
使用下面的代码成功地创建了 UTF-8 XML 文件,但是它忽略了
<!DOCTYPE dmodule[
!ENTITY % ISOEntities PUBLIC "ISO 8879-1986//ENTITIES ISO Character Entities 20030531//EN//XML" "http://www.s1000d.org/S1000D_4-0-1/ent/ISOEntities" %ISOEntities;
]>
这是我们需要的,因为信息是为图像放置的。
$files = Get-ChildItem "C:\source\*.xml"
$output = "C:\changed\"
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-Content $file;
$xml = '<?xml version="1.0" encoding="utf-8"?>' + $xml
$newFile = $output + $file.Name
Set-Content -Encoding UTF8 $newFile $xml;
}
预期结果是保留整个文档或至少在转换后获取并添加标题数据。
【问题讨论】:
-
xml文件长什么样子?
-
Doctype 遵循标题 ,如您所见,我正在替换它,并且实体转换后的所有内容都很好。只需要包含此部分或获取内容并将其复制到背面即可。
标签: xml powershell