格式良好的 XML?标记名称和属性名称中的 XML 引用 [英] Well formed XML? XML references within tag names and attribute names

查看:31
本文介绍了格式良好的 XML?标记名称和属性名称中的 XML 引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在搜索以确认我对 XML 规范的阅读.我的解释是标签名称和属性名称中不允许使用预定义的实体和数字字符引用,例如 XML 1.0 规范不允许这样做:

I have been searching trying to confirm my reading of the XML spec. My interpretation is that pre-defined entities and numeric character references are not allowed in tag names and attribute names, for example this is not allowed by the XML 1.0 spec.:

<root>
<test&apos;&#x27;&#39;tag test&apos;&#x27;&#39;attribute="one"/>
</root>

但是,我有一个解析器返回 test'''tag 标签名称和 test'''attribute 用于属性名称,而另一个解析器返回 test&apos;&#x27;&#39;tag 用于标记名称和 test&apos;&#x27;&#39;attribute 用于属性名称.

However, I have one parser that returns test'''tag for the tag name and test'''attribute for the attribute name while another parser returns test&apos;&#x27;&#39;tag for the tag name and test&apos;&#x27;&#39;attribute for the attribute name.

哪个解析器是正确的?或者他们都错了(即他们应该抛出一个格式良好的错误)?

Which parser is correct? Or are they both wrong (i.e. they should throw a well formed error)?

谢谢!

推荐答案

这很简单:名称中不能使用实体.两个解析器"在这里都是错误的.XML 规范非常清楚地定义了这一点——没有隐藏的默认规则;如果不包含某些结构,则不允许使用.

This is very simple: no entities can be used within names. Both "parsers" are wrong here. XML specification quite clearly defines this -- there are no hidden default rules; if some construct is not included, it is not allowed.

实体只能在常规字符内容和属性值中使用.并且它们可以包含在其他一些地方(注释、处理指令、DTD 子集)但不会被扩展(即不被识别为实体).

Entities can only be used within regular character content and attribute values. And they can be included in some other places (comments, processing instructions, DTD subsets) but won't be expanded (i.e. are not recognized as entities).

这篇关于格式良好的 XML?标记名称和属性名称中的 XML 引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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