XML/HTML 标记内的空白 [英] White space inside XML/HTML tags

查看:16
本文介绍了XML/HTML 标记内的空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道在 XML 和 HTML 的文本节点中如何处理空白,但我不确定标签元素本身内部的空白.显然,标签内使用空格来分隔属性,但是在'<'之后有空格是否有效还是在'>'之前?

I know how white space is handled in text nodes for XML and HTML, but I'm uncertain about white spaces inside tag elements themselves. Obviously, white spaces are used inside tags to separate attributes, but is it valid to have white spaces after '<' or before '>'?

例如:

<  foo  >
< /foo >

甚至:

<foo>
< /  foo >

这些标签是有效的 XML 吗?假设它们是实际的 HTML 标记名称,那么 HTML 呢?

Are these tags valid XML? What about HTML, assuming they were actual HTML tag names?

推荐答案

规范(第 3.1 节开始标签、结束标签和空元素标签)'<' 和标签名称之间没有空格,在 '</' 和标签名称,或在 '/>' 内.不过,您可以在标签名称后添加空格:

The specification (section 3.1 Start-tags, end-tags, and empty-element tags) says that there is no white space between the '<' and the tag name, between '</' and the tag name, or inside '/>'. You can add white space after the tag name, though:

<foo            >
</foo        >
<bar
/>

这篇关于XML/HTML 标记内的空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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