如何确保 xml 实体具有有效名称
我有一个应用程序,它根据来自我无法控制的源的一些数据生成一堆 xml。基本上,我将这些数据转换为 xml 文档,以便通过 rss feed 提供服务。我可能会获取类似的数据
2_br=1
3_br=0
,并将其转换为以下 xml
<2_br>1</2_br>
<3_br>0</3_br>
显然 xml 标签不能以数字开头。我在任何地方都找不到有效字符的列表。它存在于某处吗?我基本上只是要添加前缀和无效的起始字符,或者用 _
替换内联无效字符。
这并不难,但基本上我就是找不到 xml 标记名称的无效字符列表。
I have an app that generates a bunch of xml based off of some data from a source that I don't control. Basically I'm turning that data into an xml doc for serving via rss feeds. I may be getting data like
2_br=1
3_br=0
and I'm turning it into the following xml
<2_br>1</2_br>
<3_br>0</3_br>
Obviously an xml tag can't start with a digit. I couldn't find anywhere a list of valid characters. Does it exists somewhere? I'm basically just going to prefix and invalid starting character or replace an inline invalid character with an _
.
It's not hard to do, but basically I just cant find a list of invalid characters for an xml tag name.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样:可扩展标记语言 (XML) 1.0(第五版)
NameStartChar ::= ":" | [AZ] | “_”| [阿兹] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
How about this:Extensible Markup Language (XML) 1.0 (Fifth Edition)
NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
并可
用于验证 XML 标签名称:
and
can be used to validate a XML-tag name: