我可以通过 XSLT 将控制字符放入 XML 中吗?
我有以下问题:我有一个 XML 和一个 XSLT 文件来处理它并生成输出。
此过程的输出应包含控制字符“0B”。据我所知,XML 不嵌入控制字符,那么我该如何实现这一点呢?
I have the following problem: I have an XML and an XSLT file to process this it and generate output.
The output of this process should contain a control character '0B'. And as far as I know, XML doesn't embed control characters, so how can I accomplish this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
结果是 XML 文件吗?正如您所说,XML 不允许使用字符 U+000B。因此根据定义,任何包含该字符的文件都不是有效的 XML 文件。这里的大局是什么?为什么需要这个角色?您可以使用哪些替代方案?
如果您尝试创建一个文本文件作为XSLT 转换的结果,那就是另一回事了。
Is the result meant to be an XML file? As you say, XML doesn't allow character U+000B. So by definition, any file containing that character is not a valid XML file. What's the bigger picture here? Why do you need that character? What alternatives might be available to you?
If you're trying to create a text file as the result of the XSLT transformation, that's a different matter.
在添加到 XML 文档之前,您还可以将包含 0x0B 的有效负载编码为 Base64。
这将依赖于输出转换的使用者能够从 Base64 转换回原始编码。
You could also encode your payload containing 0x0B to Base64 before adding to your XML Document.
This would rely on the consumer of your output transformation being able to convert back from Base64 to the original encoding.
如果相关的 XML 格式支持此类字符,我希望它们驻留在某个支持 CDATA 的元素中。
你可以将你的字符放入 CDATA 部分吗? XSLT 具有用于创建 CDATA 部分 () 的构造。在内部,您可以使用 XML 实体引用对字符进行编码。
读取 XML 文件的解析器应该能够将这些实体引用转换为适当的字符。
If the relevant XML format supports such characters, I would expect them to reside in some element which supports CDATA.
Can you put your characters inside a CDATA section? XSLT has a construct for creating CDATA sections (<xsl:cdata>). Inside, you can encode your characters using XML entity references <xsl:entity-ref/>.
The parser which reads your XML file should be able to convert those entityrefs to the appropriate characters.