首页 > 开发 > Xml > 正文

快速从一个XML文件中查找信息

2020-09-19 18:01:03
字体:
来源:转载
供稿:网友
,欢迎访问网页设计爱好者web开发。

在网络时代,xml文件起到了一个保存和传输数据的作用。soap协议通过xml交流信息,数据库通过xml文件存取等等。那么怎样快速的从一个xml文件中取得所需的信息呢?

我们知道,java的jaxp中和microsoft.net都有xml分析器,microsoft.net是边读边分析,而jaxp是读到内存中然后才进行分析(还有一种是事件机制去读),总而言之,是不利于快速读取。基于此,microsoft.net 和jaxp都提供了xpath机制,来快速定位到xml文件中所需的节点。

例如有一个xml文件:booksort.xml:

<?xml version="1.0"?>

<!-- a fragment of a book store inventory database -->

<bookstore xmlns:bk="urn:samples">

<book genre="novel" publicationdate="1997" bk:isbn="1-861001-57-8">

<title>pride and prejudice</title>

<author>

<first-name>jane</first-name>

<last-name>austen</last-name>

</author>

<price>24.95</price>

</book>

<book genre="novel" publicationdate="1992" bk:isbn="1-861002-30-1">

<title>the handmaid's tale</title>

<author>

<first-name>margaret</first-name>

<last-name>atwood</last-name>

</author>

<price>29.95</price>

</book>

<book genre="novel" publicationdate="1991" bk:isbn="1-861001-57-6">

<title>emma</title>

<author>

<first-name>jane</first-name>

<last-name>austen</last-name>

</author>

<price>19.95</price>

</book>

<book genre="novel" publicationdate="1982" bk:isbn="1-861001-45-3">

<title>sense and sensibility</title>

<author>

<first-name>jane</first-name>

<last-name>austen</last-name>

</author>

<price>19.95</price>

</book>

</bookstore>

共4页: 上一页 1 [2] [3] [4] 下一页

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表