Single-Record Data Binding with the XML DSO

Starting in Internet Explorer 4, Microsoft has included an XML DSO expressly designed to be used with XML. This DSO is a little odd because it's not internal to Internet Explorer; instead, it's implemented as a Java applet. You can embed this applet in a page and create an XML DSO like this with the HTML <APPLET> element:

 <APPLET      CODE="com.ms.xml.dso.XMLDSO.class"     ID="  IDNAME  "     WIDTH="0"     HEIGHT="0"     MAYSCRIPT="true">     <PARAM NAME="URL" VALUE="  XMLPageURL  "> </APPLET> 

Here, you pass the URL of the XML document as a parameter to the XML DSO applet, using the <PARAM> element; you give this DSO a name with the <APPLET> ID attribute.

In the next example, I'll put the XML DSO to work, connecting it to ch08_03.xml. To bind ch08_03.xml to HTML elements, I start by adding the XML applet to a Web page, calling this DSO dsoCustomer . Then I pass it the URL of the document to read as a parameter:

 <HTML>      <HEAD>         <TITLE>             Single Record Binding Using the XML DSO         </TITLE>     </HEAD>     <BODY>         <CENTER>             <H1>                 Single Record Binding Using the XML DSO             </H1>  <APPLET CODE="com.ms.xml.dso.XMLDSO.class"   ID="dsoCustomer"   WIDTH="0" HEIGHT="0"   MAYSCRIPT="true">   <PARAM NAME="URL" VALUE="ch08_03.xml">   </APPLET>  .             .             . 

That's all it takes. This DSO exposes a recordset object as XML data islands do, so I can bind HTML elements to it as we've done before:

 <APPLET CODE="com.ms.xml.dso.XMLDSO.class"                  ID="dsoCustomer"                 WIDTH="0" HEIGHT="0"                 MAYSCRIPT="true">                <PARAM NAME="URL" VALUE="ch08_03.xml">             </APPLET>  Name:   <INPUT TYPE="TEXT" DATASRC="#dsoCustomer"   DATAFLD="NAME" SIZE=10>   <P>   Customer ID:   <INPUT TYPE="TEXT" DATASRC="#dsoCustomer"   DATAFLD="CUSTOMER_ID" SIZE=5>   <P>   Purchase date:   <SPAN DATASRC="#dsoCustomer"   DATAFLD="PURCHASE_DATE"></SPAN>   <P>   Department:   <SELECT DATASRC="#dsoCustomer"   DATAFLD="DEPARTMENT" SIZE=1>   <OPTION VALUE="Meat">Meat   <OPTION VALUE="Produce">Produce   <OPTION VALUE="Frozen">Frozen   </SELECT>   <P>   Product:   <SPAN DATASRC="#dsoCustomer" DATAFLD="PRODUCT_NAME">   </SPAN>  .             .             . 

I can use the recordset object's methods , such as moveNext to move to the next record and movePrevious to move to the previous one, with buttons like this. Here's the whole code:

Listing ch08_07.html
 <HTML>     <HEAD>         <TITLE>             Single Record Binding Using the XML DSO         </TITLE>     </HEAD>     <BODY>         <CENTER>             <H1>                 Single Record Binding Using the XML DSO             </H1>             <APPLET CODE="com.ms.xml.dso.XMLDSO.class"                 ID="dsoCustomer"                 WIDTH="0" HEIGHT="0"                 MAYSCRIPT="true">                 <PARAM NAME="URL" VALUE="ch08_03.xml">             </APPLET>             Name:             <INPUT TYPE="TEXT" DATASRC="#dsoCustomer"                 DATAFLD="NAME" SIZE=10>             <P>             Customer ID:             <INPUT TYPE="TEXT" DATASRC="#dsoCustomer"                 DATAFLD="CUSTOMER_ID" SIZE=5>             <P>             Purchase date:             <SPAN DATASRC="#dsoCustomer"                 DATAFLD="PURCHASE_DATE"></SPAN>             <P>             Department:             <SELECT DATASRC="#dsoCustomer"                 DATAFLD="DEPARTMENT" SIZE=1>                 <OPTION VALUE="Meat">Meat                 <OPTION VALUE="Produce">Produce                 <OPTION VALUE="Frozen">Frozen             </SELECT>             <P>             Product:             <SPAN DATASRC="#dsoCustomer" DATAFLD="PRODUCT_NAME">             </SPAN>             <P>  <BUTTON ONCLICK="dsoCustomer.recordset.moveFirst()" >   &lt;&lt;   </BUTTON>   <BUTTON ONCLICK="if (!dsoCustomer.recordset.BOF)   dsoCustomer.recordset.movePrevious()" >   &lt;   </BUTTON>   <BUTTON ONCLICK="if (!dsoCustomer.recordset.EOF)   dsoCustomer .recordset.moveNext()" >   &gt;   </BUTTON>   <BUTTON ONCLICK="dsoCustomer.recordset.moveLast()">   &gt;&gt;   </BUTTON>  </CENTER>     </BODY> </HTML> 

You can see this page at work in Figure 8-5. The XML DOS applet works as expected, but the fact that it has remained an applet external to Internet Explorer suggests that Microsoft might discard it sooner or later in favor of XML islands.

Figure 8-5. Single-record binding using the XML DSO in Internet Explorer.

graphics/08fig05.gif

As with XML data islands, you can also bind the XML DSO to tables.



Real World XML
Real World XML (2nd Edition)
ISBN: 0735712867
EAN: 2147483647
Year: 2005
Pages: 440
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net