XML相关技术学习总结

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)

转载于:https://www.cnblogs.com/wangshide/archive/2011/10/28/2228143.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值