XML 设计:描述名称中包含控制字符的文件
我正在创建一个描述文件的 XML 1.0 应用程序(例如
但我相信这是行不通的。包含特殊字符 &
、<
、'
和 "
的文件名很棘手,但您可以使用预定义实体引用 对于那些呢?包含控制字符的文件名?虽然很少见,但
在我看来,没有办法为我的目的创建 XML 应用程序,因为 XML (1.0) 不允许 控制字符在文本中的任何位置。引用 标准:
字符 ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
有什么技巧可以解决这个问题吗?它能在 XML 1.1 中工作吗,还是也有限制?
在我的 GNU/Linux 计算机上,我可以这样做来创建两个名称中带有控制字符的文件:
touch `echo -e 'SP\a'`
touch `echo -e 'SP\v'`
ls SP*
I am creating an XML 1.0 application that describes files (like others have done). At present I have a file
element that requires a name
attribute; the value of that attribute is the name of the file.
But I beleive this will not work. File-names that contain special characters &
, <
, '
and "
are tricky, but you can use the predefined entity references for those. But what about file-names that contain control characters? Although very rare, these are possible.
It seems to me there is no way to create an XML application for my purpose, because XML (1.0) does not permit the control characters anywhere in the text. Quoth the standard:
Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
Are there any tricks to get around this? Will it work in XML 1.1, or does that too have limitations?
On my GNU/Linux computer, I can do this to create two files with control characters in their names:
touch `echo -e 'SP\a'`
touch `echo -e 'SP\v'`
ls SP*
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 XML 1.1 中,您可以表示除 NUL(代码点 0)之外的所有字符。控制字符必须转义为数字字符引用。
如果您需要包括 NUL 在内的所有字符,则需要定义自己的转义约定。您可以采用 URI 中使用的约定 (%HH) 或 Java 中使用的约定 (\uNNNN),也可以发明自己的约定。
In XML 1.1 you can represent all characters except NUL (codepoint 0). Control characters must be escaped as numeric character references.
If you need all characters including NUL, you will need to define your own escape convention. You could adopt the convention used for URIs (%HH) or the convention used in Java (\uNNNN), or you could invent your own.