是否允许在 XML 属性名称中使用“!"符号? [英] Is an '!'-symbol in an XML attribute name allowed?

查看:30
本文介绍了是否允许在 XML 属性名称中使用“!"符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理来自外部方的传入 XML 消息,因此它们不是我自己编写的.我相信他们没有使用有效的 XML 语法.

I'm dealing with incoming XML-messages from an external party, so they're not authored by myself. I believe they aren't using valid XML-syntax.

考虑以下 XML:

<?xml version="1.0"?>
<MyItems>
    <MyItem !myAttributeName=""/> 
    <!--    ^ Note the '!'-mark at the beginning of 'myAttributeName'.-->
</MyItems>

我很惊讶在 XML 属性的开头看到一个感叹号.这是公然无效的 XML 吗?或者我在这里遗漏了什么?基本上所有的 XML 解析器和验证工具都无法处理这个属性名称,但我仍然很惊讶它首先被使用.

I'm surprised to encounter an exclamation mark at the beginning of an XML-attribute. Is this blatantly invalid XML? Or am I missing something here? Basically all XML-parsers and validation tools are incapable of dealing with this attribute name, but I'm still surprised that this is being used in the first place.

推荐答案

这是公然无效的 XML 吗?

Is this blatantly invalid XML?

是的.

有效名称的组成如下:

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]

NameChar        ::=         NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] |
                            [#x203F-#x2040]

Name            ::=         NameStartChar (NameChar)*

!#x21 所以它不仅不允许出现在 XML 名称的开头,也不允许出现在 XML 名称的任何位置.用 XML 术语来说,你所拥有的都是胡言乱语.

! is #x21 so not only is it not allowed at the start of an XML name, it's not allowed anywhere within one, either. In XML terms, what you have there is gibberish.

这篇关于是否允许在 XML 属性名称中使用“!"符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆