一、XML命名空间概念与应用
问题引入:在xml中,元素名称是由开发者定义的,名称很容易发生冲突。那么怎么解决呢?
①加入一些特殊的东西
②使用命名空间
下面看例子:
<table>
<tr>
<td></td>
<td></td>
</tr>
</table>
//使用命名空间之后
<table xmlns:h="http://www.sina.com">
<tr>
<td></td>
<td></td>
</tr>
</table>
//xmlns:h="http://www.sina.com" 这段就是为了唯一标识这段标签
二、DTD简介
<?xml version="1.0"?>
<note>
<to>du</to>
<from>chen</from>
<body>hello</body>
</note>
//如果想要规定上面的xml的格式,该怎么做呢?
//可以在内部加入下面的代码,也可以引入
1.内部DTD
<?xml version="1.0"?>
//规定xml必须以note为root节点,子元素为to,from,body
<!DOCTYPE note[
<!ELEMENT note(to,from,body)>
]>
<note>
<to>du</to>
<from>chen</from>
<body>hello</body>
</note>
2.外部DTD
<?xml version="1.0"?>
//引入DTD文件约束
<!DOCTYPE note SYSTEM "note.dtd">
<note>
<to>du</to>
<from>chen</from>
<body>hello</body>
</note>
由于DTD语法过于复杂和功能不够强大,逐渐被schema代替。