How to Use XML DSO to Embed Data from XML File into your HTML
PagesThe XML
DSO (XML Data Source Object) is an ActiveX control. This is built into the browser
so that you can use this ActiveX control to embed data from an XML file in to
your html web pages.
_______________________________________________
_______________________________________________
By using this
control you can create dynamic web pages that extract from the external XML file.
It is possible to write your own administration pages that can change the data
on the XML file. With this you can change the content on your web page without
going through the tedious process of doing the changes in your HTML file uploading
them through FTP programs. To
use this XML DSO, you have to initialize the XML-DSO object using the <object>
tag. This XML-DSO also has a unique CLASSID that also has to be given in the <object>
tag. The following is the tag that is to be used in your web page, <OBJECT
ID="GiveSomeID" CLASSID="CLSID:550dda30-0541-11d2-9ca9-0060b0ec3d39">
</OBJECT> By
using this object tag you can extract data from an external file or you can use
the data that is embedded in the html file itself in XML format. Let
us take a look on how to extract data from an external XML file and embed it into
your html pages using the XML-DSO object. Consider an XML file (external.xml)
given below which is the external file that will be used for our example. <?xml
version="1.0" ?> <books> <item> <bookname>Book1</bookname> <author>Author1</author> </item> <item> <bookname>Book2</bookname> <author>Author2</author> </item> </books> To
embed the data from the above xml file you have to use JavaScript to load that
external file while the web page loads. The JavaScript function can be something
like this: <script
language="JavaScript"> function loadexternalfile() { var xmlDso=myXML.XMLDocument; xmlDso.load("external.xml"); } </script> Include
the above code in the <head> section of your web page. The complete code
for the html page that includes the XML DSO and the above JavaScript is given
below: <html> <head> <title>Using
XML DSO to extract data from external XML file</title> <script language="JavaScript"> function
loadexternalfile() { var xmlDso=dataXML.XMLDocument; xmlDso.load("external.xml"); } </script> </head> <body
bgcolor="#FFFFFF" onLoad="loadexternalfile()"> <object
id="dataXML" CLASSID="clsid:550dda30-0541-11d2-9ca9- 0060b0ec3d39"> </object> <table
datasrc="#dataXML" border="1"> <thead> <th>Book
Name</th> <th>Author</th> </thead> <tr> <td><div
datafld="bookname"></div></td> <td><div datafld="author"></div></td> </tr> </table> </body> </html> In
the above code we are using the <div> tag with the attribute datafld to
specify the XML tag that contains the data that is to be displayed in the web
page. With the above code the data in the XML file is displayed in two rows since
there are two items in the external.xml file. Note that the attribute datasrc
of the <table> is set to #dataXML which is the id of the XML
DSO object used in the code. Similarly
you can use the XML-DSO object to create web pages that need to display very little
content from an external XML file. This is one of the easiest ways to display
XML data in your web page. Try this!
_______________________________________________
_______________________________________________
FREE
Subscription
Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.
Note
: We never rent, trade, or sell my email lists to
anyone.
We assure that your privacy is respected
and protected.
_______________________________________
Recommended
XML Books
|
|