如何在html5中找到空元素 [英] How to find empty elements in html5

查看:118
本文介绍了如何在html5中找到空元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是html 5中的空元素?



从下面的选项中,我可以找出空的元素?

  1。 <峰; br /> 
2.< p> < / p为H.
3.< / img>
4.< / p>

预先致谢

解决方案正如Harsh Patel指出的那样,空元素的概念来源于SGML,而HTML是基于此元素的。



在SGML中,空元素那些声明如下:

 <!ELEMENT x  -   -  EMPTY> 

或者只是

 <!ELEMENT x EMPTY> 

(其中 - - 字符是标记遗漏指标,SGML的另一个特点是不要与空元素混淆;你可以在SGML的任何文本中或在我在SGML上的现代帐户的尝试)。



SGML空元素,当遵循传统的SGML解析规则时,必须没有结束元素标记。在SGML的更新WebSGML(ISO 8879附件K)修订版中,根据功能最小化,可以容忍声明内容 EMPTY 的元素的终端元素标签EMPTYNRM 设置有效的 SGML声明(一组解析标志和SGML解析器的属性)。



ISO 8879附录K于1999年出版,旨在将SGML与XML相结合,后者是由W3C成员引入的SGML的新子集/简档,用于简化分析,目的是最终取代SGML作为HTML的基础。在XML中,声明内容 EMPTY 的元素必须具有结束元素标记,或者使用XML样式的空元素语法< x /> 表示一个起始元素标记的序列,后面紧跟着一个结束元素标记(并且WebSGML也支持该标记,但在HTML中没有意义,即使您经常会看到诸如< p ... /> 试图将标记解析为HTML和XML / XHTML)。 XML的首要目标是允许无模式解析标记,例如。消除了通过标记声明(例如上面的标记声明)告诉解析器空元素,标记省略,属性引用和其他简短形式规则的需要。



但是XHTML有点失败了广泛支持的浏览器标准(无论出于何种原因),并且在2005/2006年左右,Google领导的WHATWG浏览器供应商小组开始研究HTML 5,定义他们自己的HTML解析规则,这些规则通常不基于SGML,更不用说XML。尽管HTML 5规范没有规范地引用SGML ISO 8879标准,但HTML 5当然仍然基于SGML,现代HTML及其所有特殊规则可以像SGML一样干净地解析(参见 HTML 5.1 for HTML 5.1 HTML 5 DTD参考资料;免责声明:这是我的项目和我在XML布鲁塞尔2017年会议上发表的演讲的全文。)

W3C HTML 5.2推荐版本(每年发布一次通过W3C从 WHATWG材料),以下元素是空元素: base link meta hr br wbr img embed param track 区域 col 输入。这本质上是一组固定的元素,它永远不会改变(除了除去W3C HTML 5.2中的元素外, keygen 元素曾经是一个元素已删除HTML 5.1版本中声明的内容 EMPTY


What is empty element in html 5 ?

From the below options how can I find out empty elements?

1. <br/>
2. <p> </p>
3. </img>
4. </p>

Thanks in advance

解决方案

As Harsh Patel has pointed out, the concept of an empty element comes from SGML, on which HTML is based.

In SGML, empty elements are those declared as follows:

<!ELEMENT x - - EMPTY>

or just

<!ELEMENT x EMPTY>

(where the - - characters are tag omission indicators, another feature of SGML not to be confused with empty elements; you can read more about it in any text on SGML, or in my attempt at a modern account on SGML).

SGML empty elements, when following traditional SGML parsing rules, must not have end-element tags. In the updated WebSGML (ISO 8879 Annex K) revision of SGML, end-element tags for elements with declared content EMPTY are tolerated according to the FEATURES MINIMIZE EMPTYNRM setting of the effective SGML declaration (a set of parsing flags and properties for an SGML parser).

ISO 8879 Annex K was published in 1999 to align SGML with XML, the then-new subset/profile of SGML introduced by W3C members to simplify parsing, with the intent to eventually replace SGML as basis for HTML. In XML, elements with declared content EMPTY must either have end-element tags, or use the XML-style empty element syntax <x/> which represents a sequence of a start-element tag immediately followed by an end-element tag (and which is also supported by WebSGML, but has no meaning in HTML, even though you often see markup such as <p ... /> in an attempt to make markup parse as both HTML and XML/XHTML). The overriding goal of XML was to allow schema-less parsing of markup, eg. eliminating the need to tell a parser empty element, tag omission, attribute quoting and other short form rules via markup declarations such as the ones above.

But XHTML kindof failed as a widely supported standard for browsers (for whatever reason), and around 2005/2006, the Google-led WHATWG group of browser vendors started working on HTML 5, defining their own rules for HTML parsing which are normatively not based on SGML, much less on XML. Even though the HTML 5 specification doesn't normatively reference the SGML ISO 8879 standard, HTML 5 is of course still based on SGML, and modern HTML, with all its special rules, can be parsed cleanly as SGML (see DTD for HTML 5.1 and HTML 5 DTD reference; disclaimer: this is my project and the full paper of a talk I gave at the XML Prague 2017 conference).

In the W3C HTML 5.2 recommendation version (published yearly by W3C from WHATWG materials), the following elements are empty elements: base, link, meta, hr, br, wbr, source, img, embed, param, track, area, col, and input. This is essentially a fixed set of elements which isn't ever going to change (save for removals, eg. in W3C HTML 5.2, the keygen element which used to be an element with declared content EMPTY in the HTML 5.1 version was removed).

这篇关于如何在html5中找到空元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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