Está en la página 1de 10

Binding HTML Elements to XML Data by Using the XML DSO

Beginning in version 4, Internet Explorer has included an XML DSO designed to be used only with XML.
This DSO is unique because it's not internal to Internet Explorer and it's not an Active control!it's a
"ava applet. E#bed this applet in a page and create an XML DSO by using
the HTML <APPLET> ele#ent, li$e this%
<APPLET
CODE="com.ms.xml.dso.XMLDSO.class"
ID="IDNAME"
WIDTH="0"
HEIGHT="0"
MAYSCIPT="!"#$">
<PAAM %AME="&L" 'AL&E="XMLPageURL">
<(APPLET>
The &'I o( the XML docu#ent is passed as a para#eter to the XML DSO applet, using
the <PAAM> ele#ent. )et's ta$e a loo$ at the XML DSO at wor$ in an exa#ple. *ere's how to connect
this DSO to your XML docu#ent c)*+,0-.xml%
<HTML>
<HEAD>
<TITLE>
&s./0 !)$ XML Da!a So#"c$ O12$c!
<(TITLE>
<(HEAD>
<3ODY>
<H*>
&s./0 !)$ XML Da!a So#"c$ O12$c!
<(H*>
<APPLET CODE="com.ms.xml.dso.XMLDSO.class"
ID="states"
IDT!=""" !EI#!T="""
MA$SCRIPT="t%&e"'
<PARAM NAME="URL" (ALUE="c)*+,"-.xml"'
<.APPLET'
.
.
.
+ou can now use this DSO to bind to various controls, si#ilarly to how you have be(ore%
%am$4 <I%P&T TYPE="TEXT" DATASC="5s!a!$s"
DATA6LD="/am$" SI7E="*0">
<3><3>
Po8#la!.o/4 <I%P&T TYPE="TEXT" DATASC="5s!a!$s"
DATA6LD="8o8#la!.o/" SI7E="*0">
<3><3>
Ca8.!al4 <SPA% DATASC="5s!a!$s"
DATA6LD="ca8.!al"><(SPA%>
<3><3>
3."d4 <SELECT DATASC="5s!a!$s"
DATA6LD="1."d" SI7E="*">
<OPTIO% 'AL&E="9#a.l">9#a.l
<OPTIO% 'AL&E="C).c:ad$$">C).c:ad$$
<OPTIO% 'AL&E="3l#$1."d">3l#$1."d
<(SELECT>
<3><3>
6lo;$"4 <SPA% DATASC="5s!a!$s" DATA6LD="<lo;$"">
<(SPA%>
,inally, use the #ethods o( the record set ob-ect contained in the XML DSO .such
as mo=$%$x!, mo=$6."s!, and so on/ to navigate through the record set with buttons, as shown in
)isting 01.2.
Example 19.7. Using the XML DSO (ch19_07.html
<HTML>
<HEAD>
<TITLE>
&s./0 !)$ XML Da!a So#"c$ O12$c!
<(TITLE>
<(HEAD>
<3ODY>
<H*>
&s./0 !)$ XML Da!a So#"c$ O12$c!
<(H*>
<APPLET CODE="com.ms.xml.dso.XMLDSO.class"
ID="s!a!$s"
WIDTH="0" HEIGHT="0"
MAYSCIPT="!"#$">
<PAAM %AME="&L" 'AL&E="c)*+,0-.xml">
<(APPLET>
%am$4 <I%P&T TYPE="TEXT" DATASC="5s!a!$s"
DATA6LD="/am$" SI7E="*0">
<3><3>
Po8#la!.o/4 <I%P&T TYPE="TEXT" DATASC="5s!a!$s"
DATA6LD="8o8#la!.o/" SI7E="*0">
<3><3>
Ca8.!al4 <SPA% DATASC="5s!a!$s"
DATA6LD="ca8.!al"><(SPA%>
<3><3>
3."d4 <SELECT DATASC="5s!a!$s"
DATA6LD="1."d" SI7E="*">
<OPTIO% 'AL&E="9#a.l">9#a.l
<OPTIO% 'AL&E="C).c:ad$$">C).c:ad$$
<OPTIO% 'AL&E="3l#$1."d">3l#$1."d
<(SELECT>
<3><3>
6lo;$"4 <SPA% DATASC="5s!a!$s" DATA6LD="<lo;$"">
<(SPA%>
<3><3>
</UTTON ONCLIC0=

"states.%eco%dset.mo1e23%st45"'678s9:6lt:6lt:678s9:
<./UTTON'
</UTTON ONCLIC0="3; 4<states.%eco%dset./O25

states.%eco%dset.mo1eP%e13o&s45"'678s9:6lt:678s9:
<./UTTON'
</UTTON ONCLIC0="3; 4<states.%eco%dset.EO25
states.%eco%dset.mo1eNext45"'678s9:6gt:678s9:
<./UTTON'
</UTTON ONCLIC0=

"states.%eco%dset.mo1eLast45"'678s9:6gt:6gt:678s9:
<./UTTON'
<(3ODY>
<(HTML>
Binding HTML !ables to XML Data
Besides si#ple HTML controls, you can also bind data to #ore advanced HTML controls, such as tables.
The (ollowing exa#ple shows how to bind your state data to an HTML table, using an XML data island%
<HTML>
<HEAD>
<TITLE>
D.s8la>./0 XML da!a #s./0 XML da!a .sla/ds
<(TITLE>
<(HEAD>
<3ODY>
<H*>
D.s8la>./0 XML da!a #s./0 XML da!a .sla/ds
<(H*>
<XML SRC="c)*+,"-.xml" ID="states"'<.XML'
.
.
.
To connect the s!a!$s DSO to the table, you'll use the <TA3LE> ele#ent's DATASC attribute, li$e this%
<TA/LE DATASRC="=states" /ORDER="*"'
<THEAD>
<T>
<TH>%am$<(TH>
<TH>Po8#la!.o/<(TH>
<TH>Ca8.!al<(TH>
<TH>3."d<(TH>
<TH>6lo;$"<(TH>
<(T>
<(THEAD>
.
.
.
3ow, in the body o( the table, tie each table cell to a data (ield by using the DATA6LD attribute o(
a <SPA%> ele#ent in each <TD>ele#ent%
<TA3LE DATASC="5s!a!$s" 3ODE="*">
<THEAD>
<T>
<TH>%am$<(TH>
<TH>Po8#la!.o/<(TH>
<TH>Ca8.!al<(TH>
<TH>3."d<(TH>
<TH>6lo;$"<(TH>
<(T>
<(THEAD>
<T3ODY>
<T>
<TD'
<SPAN DATA2LD="7ame"'
<.SPAN'
<.TD'
<TD'
<SPAN DATA2LD="9o9&lat3o7"'
<.SPAN'
<.TD'
<TD'
<SPAN DATA2LD="ca93tal"'
<.SPAN'
<.TD'
<TD'
<SPAN DATA2LD="83%d"'
<.SPAN'
<.TD'
<TD'
<SPAN DATA2LD=";lo>e%"'
<.SPAN'
<.TD'
<(T>
<(T3ODY>
<(TA3LE>
And that's all there is to it. The whole exa#ple is shown in )isting 01.4.
Example 19.". Displaying XML Data in a !able (ch19_05.html
<HTML>
<HEAD>
<TITLE>
D.s8la>./0 XML da!a #s./0 XML da!a .sla/ds
<(TITLE>
<(HEAD>
<3ODY>
<H*>
D.s8la>./0 XML da!a #s./0 XML da!a .sla/ds
<(H*>
<XML SC="c)*+,0-.xml" ID="s!a!$s"><(XML>
<TA3LE DATASC="5s!a!$s" 3ODE="*">
<THEAD>
<T>
<TH>%am$<(TH>
<TH>Po8#la!.o/<(TH>
<TH>Ca8.!al<(TH>
<TH>3."d<(TH>
<TH>6lo;$"<(TH>
<(T>
<(THEAD>
<T3ODY>
<T>
<TD>
<SPA% DATA6LD="/am$">
<(SPA%>
<(TD>
<TD>
<SPA% DATA6LD="8o8#la!.o/">
<(SPA%>
<(TD>
<TD>
<SPA% DATA6LD="ca8.!al">
<(SPA%>
<(TD>
<TD>
<SPA% DATA6LD="1."d">
<(SPA%>
<(TD>
<TD>
<SPA% DATA6LD="<lo;$"">
<(SPA%>
<(TD>
<(T>
<(T3ODY>
<(TA3LE>
<(3ODY>
<(HTML>

También podría gustarte