1. 基础知识(Extensible Markup Language)
<?
xml
version="1.0"?>
<
note
>
<
to
>Tove</
to
>
<
from
>Jani</
from
>
<
heading
>Reminder</
heading
>
<
body
>Don't forget me this weekend!</
body
>
</
note
>
- 形式良好(自身的语法来保证)
- 有效性(由DTD或Schema来保证)
2. DTD(Document Type Definition)
1)内部DTD
<?xml version="1.0"?> <!DOCTYPE note [ <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> ]> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend</body> </note>
2) 外部DTD
note.xml
<?xml version="1.0"?> <!DOCTYPE note SYSTEM "note.dtd"> <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
note.dtd
<!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)>
为什么使用DTD?
- 自我描述
- 可以用于交换信息
3)XML Schema
note.xml
<?xml version="1.0"?> <note xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="note.xsd"> <--xsi:schemaLocation="http://www.w3schools.com note.xsd"--> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note>
note.xsd
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com" elementFormDefault="qualified"> <xs:element name="note"> <xs:complexType> <xs:sequence> <xs:element name="to" type="xs:string"/> <xs:element name="from" type="xs:string"/> <xs:element name="heading" type="xs:string"/> <xs:element name="body" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
为什么使用Schema?
- 支持更多的数据类型定义
- 可以使用XML Syntax
- 能保证正确地数据交换
- 可扩展的
- 形式良好并不能满足要求
上面的是http://www.w3schools.com/上的相关内容的总结。
4)文档寻址语言XPath
文档寻址语言XPath是XSL(eXtensible Stylesheet Language)家族的一员。也是XSLT, XPointer, XQuery等XML相关技术的共同基础。
从XPath角度来看,整个XML文档树由一系列节点组成。
5) XML的解析方法
- SAX(基于事件的解析方法,部分载入)
- DOM(全部载入,内存消耗太多,改进方法:载入子树,延迟读)
- XML Beans Architecture(用XML Schema生成辅助类)
- The Java Architecture For Java Binding(JAXB)
XML学习之相关技术学习总结
最新推荐文章于 2024-07-19 17:37:28 发布