在xml中,为什么有的地方用<tag content/>,有的地方用<tag>content<tag/>?
In xml, why in some case do we use <tag content/> and in some cases we use <tag>content<tag/>?
来自 Web 开发的每个 <tag>
都应该有一个结束 <tag/>
。请您详细说明何时使用哪种语法。
例子
案例一
<TextView
android:text="Hello World"
/>
案例二
<RelativeLayout>
content
<RelativeLayout/>
这两件事并不等同。在开始和结束标签之间,你可以有许多不同类型的 XML 个节点,但是在一个标签内,在 <Name
和 />
之间,你只能有 XML属性。另一方面,属性不能出现在标签之外。
<tag attribute="value">
<another-tag />
<namespace:tag> <!-- comment --> <?processing instruction?> </namespace:tag>
Text
</tag>
<closed-tag attribute="value" />
来自 Web 开发的每个 <tag>
都应该有一个结束 <tag/>
。请您详细说明何时使用哪种语法。
例子
案例一
<TextView
android:text="Hello World"
/>
案例二
<RelativeLayout>
content
<RelativeLayout/>
这两件事并不等同。在开始和结束标签之间,你可以有许多不同类型的 XML 个节点,但是在一个标签内,在 <Name
和 />
之间,你只能有 XML属性。另一方面,属性不能出现在标签之外。
<tag attribute="value">
<another-tag />
<namespace:tag> <!-- comment --> <?processing instruction?> </namespace:tag>
Text
</tag>
<closed-tag attribute="value" />