XML 中的“独立"指令是什么意思? [英] What does the 'standalone' directive mean in XML?

查看:25
本文介绍了XML 中的“独立"指令是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

standalone"指令在 XML 文档中是什么意思?

解决方案

standalone 声明是一种告诉解析器忽略 ,您会看到一个标记声明告诉解析器 标签必须是 EMPTY 并且拥有 srcalt 属性.当浏览器浏览 XHTML 1.0 文档并找到 标签时,它应该注意到 DTD 需要 srcalt属性并添加它们(如果它们不存在).它还会自动关闭 标签,因为它应该是 EMPTY.这就是 XML 规范 的意思,标记声明可以影响文件."然后您可以使用 standalone 声明来告诉解析器忽略这些规则.

您的解析器是否真的这样做是另一个问题,但符合标准的验证解析器(如浏览器)应该这样做.

请注意,如果您没有指定 DTD,那么独立声明没有意义",因此除非您还指定了 DTD,否则没有理由使用它.

What does the 'standalone' directive mean in an XML document?

解决方案

The standalone declaration is a way of telling the parser to ignore any markup declarations in the DTD. The DTD is thereafter used for validation only.

As an example, consider the humble <img> tag. If you look at the XHTML 1.0 DTD, you see a markup declaration telling the parser that <img> tags must be EMPTY and possess src and alt attributes. When a browser is going through an XHTML 1.0 document and finds an <img> tag, it should notice that the DTD requires src and alt attributes and add them if they are not present. It will also self-close the <img> tag since it is supposed to be EMPTY. This is what the XML specification means by "markup declarations can affect the content of the document." You can then use the standalone declaration to tell the parser to ignore these rules.

Whether or not your parser actually does this is another question, but a standards-compliant validating parser (like a browser) should.

Note that if you do not specify a DTD, then the standalone declaration "has no meaning," so there's no reason to use it unless you also specify a DTD.

这篇关于XML 中的“独立"指令是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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