XML / HTML标签内的空白区域 [英] White space inside XML/HTML tags

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

问题描述

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



例如:

 < foo> 
< / foo>

甚至:

 < FOO> 
< / foo>

这些标签是否为有效的XML?假设它们是实际的HTML标记名称,那么HTML又如何呢? 规范(第3.1节开始标签,结束标签和空元素标签)表示之间没有空白'< / code>和'< /'之间的标签名称以及标签名称, code> '/>'。但是,您可以在标签名称后面添加空格:

 < foo> 
< / foo>
< bar
/>


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 '>'?

For example:

<  foo  >
< /foo >

Or even:

<foo>
< /  foo >

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

解决方案

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天全站免登陆