使用 XSLT可以很容易地完成想要的“更改 XML 声明”(不评论此更改是否是解决您的问题的正确解决方案):
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" encoding="ISO-8859-1"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
只需将此转换应用于提供的 XML 文档:
<?xml version="1.0" encoding="utf-16"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master page-height="11in" page-width="8.5in" margin-top="0.50in" margin-left="0.8in" margin-right="0.8in" margin-bottom="0.25in" master-name="PageMaster">
<fo:region-body border-style="none" border-width="thin" margin-top="0in" margin-left="0in" margin-right="0in" margin-bottom="0.25in"/>
<fo:region-after border-style="none" border-width="thin" extent="0.25in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="PageMaster"/>
</fo:root>
并产生了想要的结果:
<?xml version="1.0" encoding="iso-8859-1"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master page-height="11in" page-width="8.5in" margin-top="0.50in" margin-left="0.8in" margin-right="0.8in" margin-bottom="0.25in" master-name="PageMaster">
<fo:region-body border-style="none" border-width="thin" margin-top="0in" margin-left="0in" margin-right="0in" margin-bottom="0.25in" />
<fo:region-after border-style="none" border-width="thin" extent="0.25in" />
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="PageMaster" />