【问题标题】:In xml, why in some case do we use <tag content/> and in some cases we use <tag>content<tag/>?在xml中,为什么在某些情况下我们使用<tag content/>,而在某些情况下我们使用<tag>content<tag/>?
【发布时间】:2021-09-22 22:03:00
【问题描述】:
来自网络开发的每个<tag> 都应该有一个结束<tag/>。请您详细说明何时使用哪种语法。
例子
案例一
<TextView
android:text="Hello World"
/>
案例 2
<RelativeLayout>
content
<RelativeLayout/>
【问题讨论】:
标签:
xml
android-studio
android-layout
【解决方案1】:
这两件事是不等价的。在开始和结束标记之间,可以有许多不同类型的不同 XML 节点,但在一个标记内,<Name 和/> 之间只能有 XML 属性。另一方面,属性不能出现在标签之外。
<tag attribute="value">
<another-tag />
<namespace:tag> <!-- comment --> <?processing instruction?> </namespace:tag>
Text
</tag>
<closed-tag attribute="value" />