search
HomeBackend DevelopmentXML/RSS TutorialA detailed introduction to how to use XML data source objects in web design

The xml data source object is an ActiveX control that allows you to manipulate data between XML files and HTML pages. This article will show you how to extract data from various XML data sources and how to display this data using JavaScript.

XML Data Source Object DSO is a Microsoft ActiveX control, built on Microsoft IE4 and later versions. This object allows you to extract the content of an external XML file or embedded HTML file into an HTML page.

You can use XML in a Web page - DSO selects content from an external XML file, extracts XML data from the XML embedded in the Web page, and then uses Javascript to manipulate the data. However, it is not recommended to use this object on the Internet, because DSO can only work in browsers above MSIE 4, so this may cause some compatibility issues. Therefore, it is very appropriate to use XML-DSO in the intranet.

Start

To initialize the XML-DSO object, we use the tag. The CLASSID used for XML-DSO is:

    CLSID:550dda30-0541-11d2-9ca9-0060b0ec3d39

This ID uniquely identifies XML-DSO. Use the following code to initialize this control in a Web page:

  <OBJECT ID="SomeID" CLASSID="CLSID:550dda30-0541-11d2-9ca9-0060b0ec3d39"></OBJECT>

Although most objects require many parameters to be associated with them, XML-DSO does not require any parameters.

Extracting data using an XML data island

First, include an XML data island by using the tag. Second, assign it an ID, xmldb -- for later use. The data is actually extracted using HTML tags: , ,

, etc. The code in Listing 1 uses the tag. The datasrc attribute specifies the data island from which you want to extract data. The datafld attribute specifies the XML markup of the data you want. So, the first extracts the name, and the second extracts the gender.

Code Listing 1:

<!-- example1.htm -->
<html>
<head>
<title>XML DSO-example1.htm</title>
</head>
<body bgcolor="#FFFFFF">
<xml id="xmldb">
<db>
<member>
<name>PRemshree Pillai<name>
<sex>male</sex>
</member>
<member>
<name>Vinod</name>
<sex>male</sex>
</member>
</db>
</xml>

<span datasrc="#xmldb" datafld="name"<</span>
<br>
<span datasrc="#xmldb" datafld="sex"></span>

</body>
</html>

Note that this code does not initialize an XML-DSO object. This is because the use of XML data islands has implicitly created one. The output should be:
 
 

Premshree Pillai
  male

Note that there are two and tags in the XML data island. Using this method, you can only extract the first instance of these tags. The code in Listing 2 uses the

tag to extract all instances:

The output will be:

Name Sex
Premshree Pillai male
Vinod male
在代码列表2中,<TABLE>标记使用<TD>标记内的<DIV>标记提取数据。表格将自动重复<member>(<name>和<sex>的母标记)的每个实例。 

  代码列表2:

<!-- example2.htm -->
<html>
<head>
<title>XML DSO-example2.htm</title>
</head>
<body bgcolor="#FFFFFF">

<xml id="xmldb">
<db>
<member>
<name>Premshree Pillai<name>
<sex>male</sex>
</member>
<member>
<name>Vinod</name>
<sex>male</sex>
</member>
</db>
</xml>

<table datasrc="#xmldb" border="1">
<thead>
<th>Name</th>
<th>Sex</th>
</thead>
<tr>
<td><div datafld="name"></div></td>
<td><div datafld="sex"></div></td>
</tr>
</table>

</body>
</html>

使用外部XML文件提取数据

  为了使用XML-DSO加载一个外部XML文件,你必须显式的包含这个对象并且使用一些JavaScript。 

  首先创建一个XML-DSO对象,使用ID myXML。添加宽度和高度属性到<OBJECT>标记中,然后设置它们的值为0。这保证XML-DSO对象不会占据你的Web页面的任何空间。 

  其次,使用datasrc创建一个象myXML一样的表--类似于代码列表2中一样。代码使用<DIV>标记(在TD标记之)提取数据,使用datafld作为第一栏的信息,并且使用URL作为第二栏。添加<SCRIPT>标记,因为在这里,外部的XML使用Java脚本显式地声明你想要加载的XML文件。 

  设置变量xmlDso为myXML.XMLDocument。myXML引用你已经创建的对象。接下来,使用XML-DSO的load()方法加载example3.xml。文件example3.xml连接到对象myXML上。

<!-- example3.xml -->
<?xml version="1.0" ?>
<ticker>
<item>
<message>JavaScript Ticker using XML DSO</message>
<URL>http://someURL.com</URL>
</item>
</ticker>

  现在,研究一下下面的HTML页面: 

<!-- example3.htm -->
<html>
<head>
<title>XML DSO-example3.htm</title>
<script language="JavaScript">
function load() {
var xmlDso=myXML.XMLDocument;
xmlDso.load("example3.xml");
}
</script>
</head>
<body bgcolor="#FFFFFF" onLoad="load()">

<object id="myXML" CLASSID="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" 
width="0" height="0"></object>

<table datasrc="#myXML" border="1">
<thead>
<th>Message</th>
<th>URL</th>
</thead>
<tr>
<td><div datafld="message"></div></td>
<td><div datafld="URL"></div></td>
</tr>
</table>

</body>
</html>

输出应是:

Message URL
   JavaScript Ticker using XML DSO http://someURL.com

上面的脚本非常特殊化。下面给出一个更一般的脚本: 

<script language="JavaScript">
var xmlDso;
function load(xmlFile, objName) {
eval('xmlDso='+objName+'.XMLDocument');
xmlDso.load(xmlFile);
}
</script>
Now, to load any XML file use: 
load("SomeXMLFile.xml","anyXmlDsoObject");

使用XML-DSO和JavaScript

  假设你有一个包含姓名、电子邮件地址和电话号码的XML文件。你想使用它构建一个应用程序,显示每个人的档案--一次显示一个。用户将使用"Next"和"Previous"按钮浏览每个人的数据。Javascript可以帮助你实现这个目的。 

  下面的代码使用记录集方法把文件中所有的数据保存到一个变量memberSet中。moveNext()方法指向下一个数据项(下一行)。脚本然后载入XML文件example4.xml,把记录保存到变量memberSet中。第一个记录将被显示,但是memberSet.moveNext()指向文件中相对于前一个指定数据的下一个记录。 

<!-- example4.xml -->
<?xml version="1.0" ?>
<myDB>
<member>
<name>Premshree Pillai</name>
<sex>male</sex>
</member>
<member>
<name>Vinod</name>
<sex>male</sex>
</member>
<member>
<name>Santhosh</name>
<sex>male</sex>
</member>
</myDB>

  这里是相应的HTML文件: 

<!-- example4.htm -->
<html>
<head>
<title>XML DSO-example4.htm</title>
<script language="JavaScript">
function load() {
var xmlDso=myDB.XMLDocument;
xmlDso.load("example4.xml");

/* Get the complete record set */
var memberSet=myDB.recordset;

/* Go to next data */
memberSet.moveNext();
}
</script>
</head>
<body bgcolor="#FFFFFF" onLoad="load()">

<object id="myDB" CLASSID="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" 
width="0" height="0"></object>

<span datasrc="#myDB" datafld="name"></span>

</body>
</html>

输出应是: 

Vinod

  下面给出更多使用JavaScript操作XML-DSO的方法: 

· movePrevious(): 指向前一个数据项。 

   · moveFirst(): 指向第一个数据项。 

   · moveLast(): 指向最后一个数据项。 

   · EOF: 这个属性用来检测我们是否已经到达数据记录的底部。 

使用XML-DSO和JavaScript

  假设你有一个包含姓名、电子邮件地址和电话号码的XML文件。你想使用它构建一个应用程序,显示每个人的档案--一次显示一个。用户将使用"Next"和"Previous"按钮浏览每个人的数据。Javascript可以帮助你实现这个目的。 

  下面的代码使用记录集方法把文件中所有的数据保存到一个变量memberSet中。moveNext()方法指向下一个数据项(下一行)。脚本然后载入XML文件example4.xml,把记录保存到变量memberSet中。第一个记录将被显示,但是memberSet.moveNext()指向文件中相对于前一个指定数据的下一个记录。 

<!-- example4.xml -->
<?xml version="1.0" ?>
<myDB>
<member>
<name>Premshree Pillai</name>
<sex>male</sex>
</member>
<member>
<name>Vinod</name>
<sex>male</sex>
</member>
<member>
<name>Santhosh</name>
<sex>male</sex>
</member>
</myDB>

  这里是相应的HTML文件: 

<!-- example4.htm -->
<html>
<head>
<title>XML DSO-example4.htm</title>
<script language="JavaScript">
function load() {
var xmlDso=myDB.XMLDocument;
xmlDso.load("example4.xml");

/* Get the complete record set */
var memberSet=myDB.recordset;

/* Go to next data */
memberSet.moveNext();
}
</script>
</head>
<body bgcolor="#FFFFFF" onLoad="load()">

<object id="myDB" CLASSID="clsid:550dda30-0541-11d2-9ca9-0060b0ec3d39" 
width="0" height="0"></object>

<span datasrc="#myDB" datafld="name"></span>

</body>
</html>

  输出应是: 

   Vinod

 下面给出更多使用JavaScript操作XML-DSO的方法: 

   · movePrevious(): 指向前一个数据项。 

   · moveFirst(): 指向第一个数据项。 

   · moveLast(): 指向最后一个数据项。 

   · EOF: 这个属性用来检测我们是否已经到达数据记录的底部。 

  initTicker()首先检查是否有IE 4+。如果浏览器是IE4+,这个XML文件被作为一个参数被传递并载入。如果定时器失败了,那么调用xmlDsoTicker()函数。xmlDsoTicker()除了xmlFile参数以外,和initTicker()有相同的参数,因为XML文件已经被载入。xmlDsoTicker()检查变量counter(初始值为maxMsgs)是否小于maxMsgs-1。如果是,moveNext()方法指向tickerSet中下一个数据项。 

  HTML页面的BODY包含下面的代码: 

<a href="" datasrc="#ticker" datafld="URL" class="tickerStyle">
<span datasrc="#ticker" datafld="message"></span>
</a>

图1:定时器应用程序显示输出。

  在这段代码中,<A>标记把XML文件的URL作为它的datafld。<SPAN>标记把XML文件的信息作为它的datafld。这个信息在<SPAN>元素中显示,然后整个信息可以通过这段信息相应的URL连接。 

  这样,<A>和<SPAN>元素包含下一个数据项(URL和信息)。在一段延迟以后,<A>和<SPAN>指向下一个数据。只要counter<maxMsgs-1(计数器每次递增),这个操作就会发生。如果counter<maxMsgs-1是假,计数器就被设置为0,然后指向tickerSet中的第一个数据项。 

 以上就是Web设计中如何使用XML数据源对象详细介绍的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Web Speech API开发者指南:它是什么以及如何工作Web Speech API开发者指南:它是什么以及如何工作Apr 11, 2023 pm 07:22 PM

​译者 | 李睿审校 | 孙淑娟Web Speech API是一种Web技术,允许用户将语音数据合并到应用程序中。它可以通过浏览器将语音转换为文本,反之亦然。Web Speech API于2012年由W3C社区引入。而在十年之后,这个API仍在开发中,这是因为浏览器兼容性有限。该API既支持短时输入片段,例如一个口头命令,也支持长时连续的输入。广泛的听写能力使它非常适合与Applause应用程序集成,而简短的输入很适合语言翻译。语音识别对可访问性产生了巨大的影响。残疾用户可以使用语音更轻松地浏览

web端是什么意思web端是什么意思Apr 17, 2019 pm 04:01 PM

web端指的是电脑端的网页版。在网页设计中我们称web为网页,它表现为三种形式,分别是超文本(hypertext)、超媒体(hypermedia)和超文本传输协议(HTTP)。

如何使用Docker部署Java Web应用程序如何使用Docker部署Java Web应用程序Apr 25, 2023 pm 08:28 PM

docker部署javaweb系统1.在root目录下创建一个路径test/appmkdirtest&&cdtest&&mkdirapp&&cdapp2.将apache-tomcat-7.0.29.tar.gz及jdk-7u25-linux-x64.tar.gz拷贝到app目录下3.解压两个tar.gz文件tar-zxvfapache-tomcat-7.0.29.tar.gztar-zxvfjdk-7u25-linux-x64.tar.gz4.对解

深入探讨“高并发大流量”访问的解决思路和方案深入探讨“高并发大流量”访问的解决思路和方案May 11, 2022 pm 02:18 PM

怎么解决高并发大流量问题?下面本篇文章就来给大家分享下高并发大流量web解决思路及方案,希望对大家有所帮助!

web前端和后端开发有什么区别web前端和后端开发有什么区别Jan 29, 2023 am 10:27 AM

区别:1、前端指的是用户可见的界面,后端是指用户看不见的东西,考虑的是底层业务逻辑的实现,平台的稳定性与性能等。2、前端开发用到的技术包括html5、css3、js、jquery、Bootstrap、Node.js、Vue等;而后端开发用到的是java、php、Http协议等服务器技术。3、从应用范围来看,前端开发不仅被常人所知,且应用场景也要比后端广泛的太多太多。

web前端打包工具有哪些web前端打包工具有哪些Aug 23, 2022 pm 05:31 PM

web前端打包工具有:1、Webpack,是一个模块化管理工具和打包工具可以将不同模块的文件打包整合在一起,并且保证它们之间的引用正确,执行有序;2、Grunt,一个前端打包构建工具;3、Gulp,用代码方式来写打包脚本;4、Rollup,ES6模块化打包工具;5、Parcel,一款速度极快、零配置的web应用程序打包器;6、equireJS,是一个JS文件和模块加载器。

Python轻量级Web框架:Bottle库!Python轻量级Web框架:Bottle库!Apr 13, 2023 pm 02:10 PM

和它本身的轻便一样,Bottle库的使用也十分简单。相信在看到本文前,读者对python也已经有了简单的了解。那么究竟何种神秘的操作,才能用百行代码完成一个服务器的功能?让我们拭目以待。1. Bottle库安装1)使用pip安装2)下载Bottle文件https://github.com/bottlepy/bottle/blob/master/bottle.py2.“HelloWorld!”所谓万事功成先HelloWorld,从这个简单的示例中,了解Bottle的基本机制。先上代码:首先我们从b

web浏览器是什么web浏览器是什么Sep 26, 2022 pm 05:00 PM

web浏览器是指“网页浏览器”,是一种用来检索、展示以及传递Web信息资源的应用程序;简单来说就是是用来浏览网络页面的软件。web浏览器主要通过HTTP协议与网页服务器交互并获取网页,这些网页由URL指定,文件格式通常为HTML,并由MIME在HTTP协议中指明。一个网页中可以包括多个文档,每个文档都是分别从服务器获取的。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft