Click to return to the XML (Extensible Markup Language) home page    
Web Workshop  |  XML (Extensible Markup Language)

Expanded XML Support in Internet Explorer 5


Charlie Heinemann
Program Manager, XML
Microsoft Corporation

March 18, 1999

The following article was originally published in the MSDN Online Voices "Extreme XML" column.

About a year ago today, I first got "Extreme" with you, giving you advice on how to turn good information about bad music into well-formed XML. Well, I thought I'd wax nostalgic and give you a sense of how far we've come together. There'll be a few good, old-fashioned flashbacks. And, there'll be some good new stuff: expanded XML support in Microsoft® Internet Explorer 5.

Easier Visual Basic Access to the XML Object Model

Back in June, I explained to you a little about the troubles of a cousin and in the process gave you a glimpse of some of the datatype support within the Microsoft XML parser. In that article I provided you with some Microsoft Visual Basic® code that accessed the parser and navigated some data. With Internet Explorer 5, accessing the parser and navigating the XML Object Model (XML OM) is even easier than before. There is no more casting DOMNodes to XMLDOMNodes. Now you simply have to work with four basic objects:

I've updated the article from last June, including the samples that accompany it. Take a look at the new code to see how easy it is to access XML data from a Visual Basic application. By the by, does anyone know the answer to 2 down?

DOWN
2. Marked-up information is a tad crazy. (4)

A Better Way to Post to the Server

In another article, "Happy Days Are Here Again," I described how to post XML to the server using hidden IFRAMES and long XML strings. In the meantime, however, we've developed a much easier method of posting XML to the server: the XMLHTTP object.

Using the XMLHTTP object, you can now post the XML tree itself as an object. In the following script (taken from the updated version of "Happy Days Are Here Again"), I create an XMLHTTP object and use it to post an XML tree named "template" to the server location.

var httpOb = new ActiveXObject("Microsoft.XMLHTTP");

httpOb.Open("POST","http://myServer/postCust.asp", false);
var customer = template.XMLDocument.documentElement;

customer.childNodes.item(0).text = custName.value;
customer.childNodes.item(1).text = custRelation.value;
customer.childNodes.item(2).text = custClass.value;

httpOb.send(template.XMLDocument);

The XMLHTTP object and its properties and methods are outlined in the XML reference at http://msdn.microsoft.com/xml/index.asp.

New Built-in Support for Saving Your XML Back to a File

In "Happy Days Are Here Again," once I updated the original XML using the ASP file, I saved the updated XML back to the server using the Microsoft JScript® object, FileSystemObject. This procedure required five lines of code:

SAVEDXML = CUSTLIST.xml
Set FS = CreateObject("Scripting.FileSystemObject")
Set CUSTFILE = FS.CreateTextFile(Server.MapPath
  ("customers.xml"),True)
CUSTFILE.WriteLine(SAVEDXML)
CUSTFILE.Close

With the new save method on the document, the XML can be saved with one line of code:

CUSTLIST.save(Server.MapPath("customers.xml"))

By the way, do you spell Moran with one "r" or two?

More Control over Parsing

In August, I showed you how to keep Junior from messing up your hare-brained scheme. In the article "XML, Validation, and Extra Cheese," we went through document type definitions (DTDs) and validating your data. I've updated that article to include schemas as well as DTDs--this can give you a good idea of how to use schemas to validate your data.

That brings me to the topic of parsing control. The parser in Internet Explorer 5 allows you to choose whether or not you would like to validate your data, even if it has a schema or DTD associated with it, and whether or not you would like to resolve externals such as entities. The two properties that provide this functionality, validateOnParse and resolveExternals, are independent of one another. This means that you can choose not to validate the document, but still retrieve the entities.

Check out the XML DOM reference for more information on these properties. See the XML Data reference for more information on support for validation within the XML parser that ships with Internet Explorer 5.

Transforming XML Nodes to Objects

In my February column, "Using XSL to Sort and Filter Your Data," I explained how you can use XSL to sort and filter data for the XML Data Source Object (XML DSO). In that article, I bound to XML that had been transformed using XSL by loading the new XML as a string with the loadXML method. I had to do this because transformNode returned the XML as a string only:

xmldso.loadXML(xmldoc.documentElement.transformNode
  (xsldoc.documentElement));

Expanding the XSL support within the XML object model, we now provide a method of transforming XML into an object. This means that I can call on the node to be transformed, and pass that method the stylesheet and object to contain the new tree as the parameters:

xmldoc.documentElement.transformNodeToObject
  (xsldoc.documentElement,xmldso.XMLDocument);

The XML Document Object, xmldso, now contains the new transformed XML as a tree. No more having to deal with long BSTRs, or converting objects to strings and back to objects again.

Waxing Nostalgic

Looking back on the year, I must say it's been amazing. My Uncle Edd's pizza business is still afloat and fewer cousins are calling me out of the blue. The XML support within Internet Explorer 5 has grown substantially. We now have XSL and query support, full DOM support, schemas, a way to browse XML directly, and a brand new higher-performance DSO.

With Internet Explorer 5 it is now possible to create a true XML-based Web application. To prove just that, we have a demo available that is exactly that: an XML-based Web application. Check it out at http://www.microsoft.com/xml/somewhere.asp. Particularly cool is the Microsoft Agent that reads your sports information to you. The information is in XML, and XSL is used to transform the XML into Microsoft Agent code.

Charlie Heinemann is a program manager for Microsoft's Weblications team. Coming from Texas, he knows how to think big.



Back to topBack to top

Did you find this material useful? Gripes? Compliments? Suggestions for other articles? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.