Article

XML and Web Services for Microsoft Developers - Part 1

Page: 1 2 3 4 5 6 Next

Using MSXML on the Client Side

Let's assume that you're working on a Windows application that periodically needs to connect to a Web server, download some configuration details, and refresh the same on the client side. Let's also assume that these configuration settings are saved as an XML document on the server. So the task in hand is to download this XML document from the server, and save it on the client side as a disk file. The following Visual Basic application does the exactly same job:

Start Visual Basic 6.0, create a new standard EXE project, and add reference (Project | References...) to Microsoft XML, v4.0 (msxml4.dll). Double click on the form and write the following code in the Form_Load() method:

Const strURL = "http://www.PerfectXML.com/books.xml"  
 
'Create MSXML DOMDocument instance  
Dim objXMLDoc As New MSXML2.DOMDocument40  
 
'Set Properties  
objXMLDoc.async = False  
objXMLDoc.validateOnParse = False  
objXMLDoc.resolveExternals = False  
 
'Since loading over HTTP from a remote server  
objXMLDoc.setProperty "ServerHTTPRequest", True  
 
If objXMLDoc.Load(strURL) Then  
   objXMLDoc.save "c:\books.xml"  
   MsgBox "Remote XML document saved as c:\books.xml."  
Else  
   MsgBox "Error: " & objXMLDoc.parseError.reason  
End If  
 
Unload Me

The above Visual Basic code, like ASP page example, uses MSXML DOM to load the XML document. The important point to note is that, as we're loading a remote XML document over HTTP, we must set the ServerHTTPRequest property to True. If the document load succeeds, the save method is called to persist the loaded XML document on the client side as c:\books.xml.

We just saw an example that used MSXML on the client side in a Visual Basic application. Let's now focus on using XML inside the browser client.

If you liked this article, share the love:
Print-Friendly Version Suggest an Article