需要从 xml 中删除 <?xml version="1.0" encoding="utf-16"?>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14800746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Need to remove <?xml version="1.0" encoding="utf-16"?> from the xml
提问by shaiksha
Hi i am generating a xml by appying the xsl to a xml input. I need the output without this part "<?xml version="1.0" encoding="utf-16"?>"
嗨,我正在通过将 xsl 应用到 xml 输入来生成 xml。我需要没有这部分的输出"<?xml version="1.0" encoding="utf-16"?>"
input--xml
输入--xml
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CreateResponse xmlns="http://jerseytelecom.com/">
<CreateResult>
<ISD_XMLGateway>
<Entity>RIM_BPS</Entity>
</ISD_XMLGateway>
</CreateResult>
</CreateResponse>
</soap:Body>
</soap:Envelope>
my xsl
我的 xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:JT="http://jerseytelecom.com/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="JT">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:element name="Entity">
<xsl:value-of select="soap:Envelope/soap:Body/JT:CreateResponse/JT:CreateResult/JT:ISD_XMLGateway/JT:Entity"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Current output
电流输出
<?xml version="1.0" encoding="utf-16"?>
<Entity>RIM_BPS</Entity>
Expected Output
预期产出
<Entity>RIM_BPS</Entity>
回答by ChrisC
Try adding the omit-xml-declaration="yes"attribute to your xsl:outputtag.
尝试将omit-xml-declaration="yes"属性添加到您的xsl:output标签中。
It should then read like this:
然后它应该是这样的:
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
回答by Tony Hopkinson
Put this in your xslt
把它放在你的 xslt 中
<xsl:output method="xml" omit-xml-declaration="yes"/>
or
或者
at an extreme push
在极力推动下
<xsl:output method="text" />
should solve the symptom...
应该可以解决症状...
The last one could have significant consequences though depending on the processor.
尽管取决于处理器,但最后一个可能会产生重大后果。
回答by Abhishek Kumar
Use this XSLT to remove encoding=“UTF-8” from xml Document using XSLT.In Cdaata section You can add encoding as your will. Cheers:)
使用此 XSLT 从使用 XSLT 的 xml 文档中删除 encoding=“UTF-8”。在 Cdaata 部分中,您可以根据需要添加编码。干杯:)
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:text disable-output-escaping="yes"><![CDATA[<?xml version="1.0"?>]]></xsl:text>
<xsl:copy-of select="node()"/>
</xsl:template>
</xsl:stylesheet>
回答by Dimitre Novatchev
This complete transformation:
这个完整的转变:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:JT="http://jerseytelecom.com/" exclude-result-prefixes="soap JT">
<xsl:output omit-xml-declaration="yes" indent="yes"
encoding="utf-8"/>
<xsl:template match="/">
<Entity>
<xsl:value-of select=
"soap:Envelope/soap:Body/JT:CreateResponse
/JT:CreateResult/JT:ISD_XMLGateway/JT:Entity"/>
</Entity>
</xsl:template>
</xsl:stylesheet>
when applied on the provided XML document:
当应用于提供的 XML 文档时:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<CreateResponse xmlns="http://jerseytelecom.com/">
<CreateResult>
<ISD_XMLGateway>
<Entity>RIM_BPS</Entity>
</ISD_XMLGateway>
</CreateResult>
</CreateResponse>
</soap:Body>
</soap:Envelope>
produces the wanted, correct result:
产生想要的、正确的结果:
<Entity>RIM_BPS</Entity>

