XML and XSL with ASPBy Gurpreet Kanwar
|For more information on XML be sure to check out the 4Guys XML Article Index!|
This article explains in a very simple manner how you can use XML in ASP and VB. Since the inception of XML people many developers have wondered why we need XML... How is it better than HTML? For starters, XML is far more powerful than HTML, and that power resides in the "X" in XML (which stands for "eXtensible"). Rather than providing a set of pre-defined tags, as in the case of HTML, XML specifies the standards with which you can define your own markup languages with their own sets of tags. XML is therefore a meta-markup language, allowing you to define an infinite number of markup languages based upon the standards defined by XML.
XML was created so that richly structured documents could be used over the web. The only viable alternatives, HTML and SGML, are not practical for this purpose. XML allows you to define all sorts of tags with all sorts of rules, such as tags representing business rules or tags representing data description or data relationships
As with any technology, XML has its own acronym-riddled lingo. Some of the important acronyms to know include:
- DTD - In XML, the definition of a valid markup is handled by a Document Type Definition (DTD), which communicates the structure of the markup language. The DTD specifies the validity of each tag.
- XSL - The Extensible Style Language (XSL) is the style language for XML.
- XML Pointer Language (XPointer) and XML Linking Language (XLink) - these two technologies define a standard way to represent links between resources.
In addition to simple links, like HTML's
<A>tag, XML has mechanisms for links between multiple resources and links between read-only resources. XPointer describes how to address a resource; XLink describes how to associate two or more resources.
- XML Flow Architecture - XML offers a three-tier architecture. It can be generated from existing databases using 3-tier model. We can maintain business rules separately
Why XML Should Be Used
XML contains a bevy of benefits. Some of the most profound benefits include:
- Authors and providers can design their document using XML, instead of being stuck with HTML. They can be explicitly tailored for an audience, so the cumbersome problems with HTML can evaporate: therefore, authors and designers will be free to invent their own markup elements.
- Information can be richer and easier to use, because the hypertext linking abilities of XML are much greater and simpler than those of HTML.
- XML can provide more (and better) facilities for browser presentation and performance.
- XML certainly compresses exceedingly well. Since data compression algorithms operate on the concept of maximizing the entropy of a given input stream, it stands to reason that a highly ordered input stream consisting of regular, repeating tag sequences will compress exceedingly well- much better than standard text which contains generally far less order thus increase in performance.
XML is, obviously, not a cure-all, free of disadvantages... else we would be using XML and nothing else! There are some drawbacks and weaknesses of XML:
- XML markup can be incredibly verbose, depending on the vocabulary in question.
- XML is platform-neutral
- All the pieces aren't yet in place to do whatever you want with XML - certainly not in a fully standards-compliant form, anyhow.
We've got XSL/XSLT but they are not fully developed yet.
- There are still some problems with Microsoft XML Parser July release.
- XML Hypertext Transfer Protocol (XML-HTTP) problems still exist.
Performance of XML
When you are designing your XML-based Web application and you need to know what kind of performance to expect from your XML server. It is hard to generalize, because there are so many variables -- such as the size of the XML documents, the amount of script code required to process the documents, the amount of output generated, etc. For example, major variables that can affect the performance of MSXML include:
- The Kind of XML Data
- The ratio of tags to text
- The ratio of attributes to elements
- The amount of discarded white space
XML and DOM
Microsoft has provided us DOM (Data Object Model for XML). With the XML Document Object Model (DOM), you can load and parse XML files, gather information about those files, and navigate and manipulate those files. To know about the details of XML DOM, please refer to the XML DOM site at Microsoft's site: http://msdn.microsoft.com/xml/.
We are going to create an XML file using static data and Data from Database using ADO.
The DOM methods
appendChild, and the
text property are used to construct an XML tree.
Now that we've discussed the reasons for using XML, it's time to look at some source code! In Part 2 we will examine some ASP scripts that create and display XML data!