xmlns属性是做什么的? [英] What does the xmlns attribute do?
问题描述
$ b
xmlns属性指定一个文档的xml命名空间。
这基本上有助于避免不同xml文档之间的命名空间冲突,例如,如果开发人员将xml文档来自不同的XML应用程序。
这个例子(也来自W3网站):
定义一个html表格:
< table>
< tr>
< td>苹果< / td>
< td>香蕉< / td>
< / tr>
< / table>
用于定义咖啡桌信息的XML数据
<表>
<名称>非洲咖啡桌< /名称>
< width> 80< / width>
< length> 120< / length>
< / table>
这里有两个表格元素,这会产生冲突。为了解决这个问题,您可以添加一个名称空间来表示哪一部分信息定义了一个html表格,其中包含有关茶几信息:
<根>
< h:tr>
< h:td>苹果< / h:td>
< h:td>香蕉< / h:td>
< / h:tr>
< / h:表格>
< f:姓名>非洲咖啡桌< / f:姓名>
< f:宽度> 80< / f:宽度>
< f:长度> 120< / f:长度>
< / f:table>
Validation requires that I set it but why? I like to think the code in my xhtml document is doing something.
From the W3Schools:
the xmlns attribute specifies the xml namespace for a document.
This basically helps to avoid namespace conflicts between different xml documents, if for instance a developer mixes xml documents from different xml applications.
An example of this (also from the W3 website):
XML data to define an html table:
<table>
<tr>
<td>Apples</td>
<td>Bananas</td>
</tr>
</table>
XML data to define information about a coffee table
<table>
<name>African Coffee Table</name>
<width>80</width>
<length>120</length>
</table>
There are two table elements here, which would produce a conflict. To fix this, you can add a namespace to signify which piece of information defines an html table and which comprises information about a coffee table:
<root>
<h:table xmlns:h="http://www.w3.org/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="http://www.w3schools.com/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
这篇关于xmlns属性是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!