简体   繁体   English

我们可以有一个嵌套的html标签吗?

[英]can we have a nested html tag?

I am parsing and html/xml file. 我正在解析和html / xml文件。 I am bit confused with the fact that can we have a nested tag like this. 我对我们可以拥有这样的嵌套标签感到困惑。

<A a="#" b="#".....<xyz>...</xyz> />

If yes can you please point out me the place where I could get information about this. 如果可以,请给我指出我可以获得有关此信息的地方。

No you cannot. 你不能。 Other than the tag name and an optional closing ( /> ) the only thing allowed inside of the tag it self are attributes which take the form key=val . 除了标签名称和可选的结束( /> )之外,标签本身允许的唯一属性是采用key=val形式的属性。 If you want to have < or > in a tag's attributes then they need to be encoded as &lt; 如果要在标记的属性中包含<> ,则需要将其编码为&lt; and &gt; &gt;

Nested tags have to be done like so 嵌套标签必须这样处理

<root>
   <child></child>
</root>

A tag that has a /> is called self closing, this means it has no children 带有/>标签称为自我关闭,这意味着它没有子代

It is not “well-formed XML,” ie XML at all. 它不是“格式正确的XML”,即根本不是XML。 A tag cannot contain tags. 标签不能包含标签。

In HTML up to and including HTML 4.01, if parsed by the specifications (no browser does this), it would be somewhat different. 在不超过HTML 4.01的HTML中,如果按规范进行解析(没有浏览器会这样做),则将有所不同。 A tag cannot contain a tag, but the < would implicitly close the a tag (tag, not element). 标签可以不包含标签,但<将隐含关闭a标签(标签,而不是元素)。 There would still be an error due to lack of closing </a> tag. 由于缺少</a>标记,仍然会出现错误。 The characters /> would be taken as data characters, not markup. 字符/>将被视为数据字符,而不是标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM