1.xml声明 小写 <?xml version="1.0" ?/>
节点: 元素,属性,元素内的文本
注意
- 只能有1个顶级节点
- 属性必须有引号
- 必须有关闭标记
2. XML 名称空间
http://www.wrox.com"> //wrox空间里的book元素 <wrox:title>Beginning C#</wrox:title> <wrox:author>Karli</wrox:author> </book> </books>
3.验证XML文档
定义XML文档中可以放置哪些元素和属性,以及其放置顺序。
主要有 文档类型定义(DTD) 和 模式。
DTD不允许规定元素和属性的数据类型,所以主要用模式。
Net支持的模式有2种;XSD (W3C标准)和XDR(老标准,只能用与微软)。
xsd 可以放于XML文档,也可以单独文件。
2必须.
- XSD模式元素必须属性名称空间 http://www.w3.org/2001/XMLSchema
- XML使用XSD 要在 顶级元素加上 schemalocation="xx\books.xsd"
根据XML创建XSD模式
?> <stores> <story> <title>story1</title> <author> <name>sheridan</name> <country>USA</country> </author> </story> <story> <title>story2</title> <author> <name>wd</name> <country>Japan</country> </author> </story> </stores>
?> <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="stores"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" name="story"> <xs:complexType> <xs:sequence> <xs:element name="title" type="xs:string" /> <xs:element name="author"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="country" type="xs:string" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>