Simon Bisson took a trip to the 1998 Microsoft PDC in Denver to see what Microsoft is planning for the next generation of NT-based Internet applications and discovered how Microsoft plan to use XML and XSL.
Five days in a big building…
With a title of “Building Windows-based Applications For The Internet Age”, the 1998 Microsoft Professional Developers Conference promised a lot. By the time the attendees finally left the complex of conference halls in Denver, they’d had 5 days of a mix of marketing-led and deep technical briefings – as well as dealing with the thin air of the Mile High City. With presentations starting at 8 am, and finishing at nearly 7 pm, most of them hadn’t so much as glanced at the snow-capped peaks of the Rockies that dominate the Denver skyline…
The key Internet application development theme of the conference was Microsoft’s announcement of its commitment to XML, and several packed out sessions looked at how Internet Explorer was using XML and XSL to handle complex data, as well as examining how to use XML in the middle-tiers of multi-tier applications. Another track looked at the new technologies being introduced in Internet Explorer 5.0, as well as introducing the next release of the Internet Information Server web server, IIS 5.0 which will be included with NT 5.0.
As they’ve doing for some time now, Microsoft chose to use the PDC to evangelise for their DNA distributed application architecture. With demonstrations of the latest versions of the Visual Studio Tools, and the Transaction Server combined transaction monitor and ORB, they showed how to build enterprise Internet applications. Part of the demonstrations were intended to show how the next release of the COM software component model would operate, including showing its dynamic load balancing features – a crucial feature missing from earlier releases. Unfortunately COM+ won’t be available in general release until after the release of NT 5.0, but technology preview versions of the main Visual Studio tools will be available before then, so you can start to work with these technologies before you need to deploy them in your NT-based Internet applications.
Windows everywhere? XML everywhere!
However, it was Microsoft’s newly found commitment to all things XML that attracted the attention of most of the attendees. In fact, the presentations were so popular that they had to be re-shown at night through the TV systems of hotels full of developers, as queues of prospective attendees had to be turned away.
A key presentation covered Microsoft’s implementation of the recently released XSL standard, as well as the implementation of XML document schema. Currently Microsoft’s focus is on using XML to transmit data to a client, and to use it as a neutral interchange format when working with heterogenous systems that may contain complex legacy applications.
As XML uses a hierarchical tree structure, with a strict parser you will need to create well-formed XML documents. This means that planning the logical model of any XML document is an important phase in creating an XML application – so you will need to know what the purpose of a document is before you begin to define the XML tags required.
Once you’ve defined the structure of your XML document, you will need to create a schema so that high-level information about the structure of your document can be transmitted. A typical XML schema is shown below:
<Schema name="MySchema" xmlns="urn:schemas-microsoft-com:xml-data"xmlns:dt=" urn:schemas-microsoft-com:xml-datatypes"> <ElementType name="title" content="textOnly" dt:type="string"/><ElementType name="artist" content="textOnly" dt:type="string"/> <ElementType name="id" content="textOnly" dt:type="int"/><ElementType name="category" content="textOnly" dt:type="string"/> <ElementType name="date" content="textOnly" dt:type="date"/><ElementType name="album" content="eltOnly" order="many"> <element type="title"/><element type="artist"/><element type="id"/><element type="category"/> <element type="date"/></ElementType></Schema>This defines how an XML schema fits into an XML namespace, and then defines the structure and elements of an XML data type. Here an XML document for a record catalogue is being defined, with a mix of string, integer and date elements that are then bundled up into an “album” element.
Of course, defining an XML document is only part of the problem, as you’ll need to be able to be able to display it. An XML parser has been included in Microsoft’s browsers since IE 4.0, though initially this was very simple. The next preview release of IE 5.0 (due sometime in November 1998) will have an improved version of this, and will include support for XSL. Support for “Data Islands” will allow you to embed XML in your HTML, either directly or as external files.
Loading an XML file in an application can be handled by two main techniques. You can use the document object model to load in a file using scripting technologies:
xml = new ActiveXObject("Microsoft.XMLDOM");//If async, trap onreadystatechange//Load the XML fileif (!xml.load("records2.xml")) alert(xml.parseError.reason)The code snippet shown here loads in the XML parser, and then loads an XML document. By checking for a return code, you can display errors using the xml.parseError.reason method. As the XML parser is asynchronous by default, you will need to use the onreadystatechange event to handle when to start parsing the XML file – especially if a page or scriptlet is handling multiple related events.
An alternative (and somewhat simpler) approach is to use data islands. This uses an extension to standard HTML to import an XML file into an HTML page:
<XML id="data" src="records2.xml"></XML>Using the XML tag, you can point a page at an external XML data source. It you’re scripting a data island you will need to use the onreadystatechange event to allow pages to handle the asynchronous loading of the XML file.
Once an XML file has been included in your page, you can then display it. Four techniques are available. You can use the DHTML data binding techniques that were intrioduced in IE 4.0, or use scripts and the document object model, or use XSL, or treat an XML document as a MIME document and use IE 5.0’s internal XML parser directly.
Using the document object model can be a little tricky, as you need to understand the document hierarchy in order to build your XML parsing scripts. It’s here that an XML schema comes in useful, and you can either use it to manaually create the code you need to parse the document tree, or develop a generic script that uses the schema to develop parsing rules for a document. Microsof thave provided some proprietary DOM extensions to make scripting XML easier, and these include node navigation tools.
It’s also possible to use the DOM to handle more complex uses of XML, by using XSL-style syntax to include filters in a script. XSL filters are a simple query language that uses C-style Boolean logic.
Of course, if you’re going to use scripting with embedded XSL to display the contents of an XML file, you’re probably better off learning how to use XSL itself! XSL is the eXtensible Style-sheet Language, and is designed to take any XML document tree, and transform it to another. Tags in the XSL sheet control this tree-to-tree transform.
An XSL stylesheet is a container, holding an overall XML document template, and specific XSL commands and templates. These can be used to control the display of data stored in an XML file.
A typical XSL file is shown below:
<XML id="style"><?xml version="1.0"?><xsl:template xmlns:xsl="uri:xsl"><TABLE> <THEAD><TD>Album</TD><TD>Artist</TD></THEAD><xsl:for-each select="xml/album"> <TR><TD class="title"><xsl:value-of select="title"/></TD><TD class="artist"><xsl:value-of select="artist"/></TD></TR> </xsl:for-each></TABLE></xsl:template></XML>This will examine the contents of an XML album database document created with the schema shown earlier, and display the results in an HTML table. You can also use this technique to add more complex operations and CSS styles to a displayed document:
<xsl:for-each select="xml"><TR><xsl:use-templates for="album" order-by="+category;+title"/></TR></xsl:for-each> <xsl:template match="album[category='Rock']"><TR style="background-color:lightblue"><TD><xsl:value-of select="title"/></TD> <TD><xsl:value-of select="artist"/></TD><TD><xsl:value-of select="category"/></TD></TR></xsl:template>Here, the code snippets from an XSL stylesheet are showing how you can use XSL to both sort an XML document, and then to apply different display templates for each category. Using the template format shown above, each type of music displayed in a table can have separate background colours when displayed in an XML and XSL aware browser.
You can also use IE 5.0’s built in XML parser to display XML documents and apply SSL style sheets. All you need to do is add this line to the start of any XML document you intend to use this way:
<xml:stylesheet type="text/xsl" href="style1.xsl"?>This allows an XSL stylesheet to be applied directly to your XML document (where “style1.xsl” is replaced by the filename of your chosen style sheet).
Using XML in the browser is all very well, but you do need to be able to deliver it to the client. One option is to use ASP pages to create XML on the fly, as part of an ADO query as normally used to generate server-driven HTML:
Set Conn = Server.CreateObject("ADODB.Connection")Conn.Open "Auction","auction","auction"Set ItemRS = Conn.Execute("select * from item") <ARTIST><%=ItemRS("Artist")%></ARTIST>Here an XML document is being created by a simple database query. You will need to handle this carefully, as 3.0 browsers will have difficulty parsing XML. In order to handle this effectively you will need to write content negotiation driven sites that will only deliver XML to a capable browser.
Where browsers can’t handle XML, you can use server side ASP scripts to parse the document and apply XSL templates prior to delivery to the browsers as HTML. By selecting your filters appropriately you can handle a wide range of browsers from a single XML-aware ASP page. You will need to have the XML parser installed on your server in order to do this, as it will need to be called as an in-page object by the ASP scripting-engine. Similar techniques can be used to “chunk” large XML documents, sending them to the client as groups of XML nodes.
The use of XML and XSL in the browser will allow you to develop complex data-driven web pages without the complexity of large scripts and DHTML data binding. When tied into the DHTML behaviours introduced in IE 5.0, you can handle a wide range of business-logic and display logic in the browser, reducing the load on your servers.
The all-seeing eye of the Visual Studio Analyser.
Building distributed Internet applications is often the easy part – it’s when you start debugging that problems can arise. Is it the server components, the database, or the browser scripts that are causing the problems? One of the more entertaining and technically illuminating presentations at the PDC was an introduction to a new feature of the Visual Studio 6.0 Enterprise edition. The Visual Studio Analyser is designed to link into the Windows operating system, monitoring several different layers. These include:
You can also add your own information sources, either using your own COM events or RPC to monitor remote legacy systems, as well as by using the NT PerfMon performance monitor.
Once you’ve set up information sources, and started up the Analyser, all you need to do is run your application. As it runs at an operating system level, Analyser traps and logs all relevant events, associating them with a project. Once collected, you can then explore how your application has performed, by drilling down into the recorded data. As Windows contains a lot of monitoring hooks, there can be a lot of data in an Analyser log file, so you’ll need to choose filters to create a relevant subset of data for viewing.
You can use Analyser to give you several different views of how your application is running. The simplest approach is to use the event viewers, which give you a list of events that have occurred, as well as showing you a timeline of events. This helps you develop an understanding of the density of events occurring in your application, and to help you focus on possible problems.
For a deeper view, Analyser’s chart view is a good place to start exploring how an application’s performed. This uses a tree-based version of the event list to display a Gantt chart of the relationships between events. Parent events can be expanded to show how their children perform, and you can overlay PerfMon data to show how these events relate to processor loading and memory usage. One thing to remember is that all events listed in the Visual Studio Analyser are deduced – so there may be inaccuracies, as not everything is monitored.
You can also use Analyser to create an application block diagram. This is deduced from an analysis of the event flow within a distributed application, and allows you to play back events, as well as to drill down into more detailed views. Using this you can display an application’s behaviour at machine, process and component level.
Visual Studio Analyser isn’t a debugging tool or a profiler in it’s own right. As Martin Lovell of Microsoft says, “It’s about pointing the finger of blame”. You can use Analyser to track down problematical areas of your application, and then run a separate debugger to explore the exact cause of any problems. You can also use it as an educational tool for new developers, as its animated block diagrams will show how a program’s components interact.
You don’t even need to own the whole application you’re monitoring. It’s possible to use the Analyser from a browser alone, so you could spend some time seeing how sites like microsoft.com behave!
Squawk! It’s a digital parrot!
A lighter touch was the first public appearance of the 2.0 release of the Microsoft Agent animated character system, as presented by Peedee, the Personal Digital Parrot. Whilst it remains at heart a whimsical piece of animation programming, the latest version adds new interfaces and a new object model that makes it easier to include in web applications. With a COM server as well as the ActiveX control, Agent 2.0 can be used from Java and C++ applications as well as scripted web pages and Visual Basic programs. As Agent 2.0 is now part of the Office 2000 help system, it will become a familiar part of users’ desktops over the next couple of years. If you’re developing a complex web application, or building a corporate Intranet, using the Agent 2.0 characters would give users similar user interfaces for both their key desktop applications and the web-applications they use.
Summary
