Using the XML Data Source Object

To use the XML data source object, you'll need to ensure that you have the XMLDSO.class file installed on your Web server. You can obtain this class file by downloading the Microsoft XML Parser in Java from the Microsoft Web site. After installation, the class file should be located in the following folder: c:\msxml\classes\com\ms\xml\dso.

Now all we need to do is to create an XML file to use as our data file, an HTML file that contains the XML data source applet, plus some data-bound HTML elements to display the data. The code below shows the source code for xml.htm. This file is included on the CD-ROM under the CHAP16 folder along with the other relevant files.

 <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> <TITLE></TITLE> </HEAD> <BODY> <H2>Simple Table (Using XML Data Source Object)</H2> <HR> <APPLET CODE=com.ms.xml.dso.XMLDSO.class     ID="xmldso"     WIDTH="0"     HEIGHT="0"     MAYSCRIPT="true">     <PARAM NAME="url" VALUE="xml.xml"> </APPLET> <TABLE ID=table border=2 width="50%" datasrc=#xmldso cellpadding=5> <THEAD> <TH>1st</TH> <TH>2nd</TH> </THEAD> <TR> <TD><SPAN datafld="FIRST" dataformatas="HTML"></SPAN></TD> <TD><SPAN datafld="SECOND" dataformatas="HTML"></SPAN></TD> </TR> </TABLE> </BODY> </HTML>  

You'll notice in the code that the <APPLET> tag is used to define the XML data source object. The URL attribute in the <PARAM> tag is used to specify the URL location of the XML file to read. In this case, the file is named xml.xml and the contents are the same as the sample XML file listed earlier in this chapter. The width and height of the applet are set to 0 so that the applet does not display on screen.

Notice that an HTML table is used to display the data from the XML file. The DATASRC attribute of the table element is set to #XMLDSO, which is the name assigned to this XML data source applet. The DATAFLD attributes for the table cells are set to FIRST and SECOND. These are the names of the tags that were defined in the XML file. The DATAFORMATAS attribute has been set to HTML.

Figure 16-4 shows the HMTL page as it appears in the Internet Explorer 4.0 browser.

As you can see from this sample, it is very easy to write HTML code that can read an XML file and display the data on screen. The powerful part of this technique is that it is extensible. The XML file can use whatever tags are necessary to represent the data structures involved.

click to view at full size.

Figure 16-4. The xml.htm file, which uses the XML data source object to display the data from an XML file.



Programming Microsoft Visual InterDev 6. 0
Programming Microsoft Visual InterDev 6.0
ISBN: 1572318147
EAN: 2147483647
Year: 2005
Pages: 143

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