MSXML and Namespaces


Starting with MSXML 3.0, you might find that the returned information from Exchange cannot be parsed because MSXML has removed support for the data type namespace that Exchange 2000 and 2003 returns, which is urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/ . MSXML uses the new data type namespace, urn:schemas-microsoft-com:datatypes . You will also find that Exchange 2000 and 2003 return some property names beginning with 0, such as 0x12345678 . This is invalid XML.

To work around these errors, you must replace the data type namespace returned by Exchange (and also Microsoft SharePoint Portal Server 2001), and you must remove any invalid XML that starts with 0. Also, if you are using the XMLDOM, you should set the validateOnParse property to false so MSXML will not attempt to validate all the XML nodes while parsing through the document. The following code shows how to perform all these steps:

 Set request = CreateObject("Microsoft.XMLHTTP")      request.Open "PROPFIND", _              "http://localhost/public/my%20new%20folder%202/" _ & "my%20new%20item.eml"      request.setRequestHeader "Content-Type", "text/xml" request.setRequestHeader "Translate", "f"      body = "<?xml version=""1.0"" encoding=""utf-8""?>" _      + "<a:propfind xmlns:a=""DAV:""><allprop/></a:propfind>"      request.send body      Dim oXMLDOM As New MSXML.DOMDocument strXML = request.responseText      'Replace the UUID stuff with urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/ strXML = Replace(strXML, "urn:uuid:c2f41010-65b3-11d1-a29f-00aa00c14882/", _                  "urn:schemas-microsoft-com:datatypes") strXML = Replace(strXML, "0x", "x")      oXMLDOM.validateOnParse = False oXMLDOM.loadXML strXML 

Another way to work with and manipulate namespaces is by using the NamespaceManager object included with MSXML. The namespace manager allows you to push and pop namespaces for your current local context. The following code sets the prefix of the urn:schemas:httpmail: namespace to d .

 oNSManager.declarePrefix "d", "urn:schemas:httpmail:" 

Another option you have with MSXML is to have the MSXML parser remap the prefixes to ones that you define. For example, the following code sets the prefixes for the DAV and office namespaces:

 oXMLDOM.SetProperty "SelectionNamespaces", "xmlns:d='DAV:'" & Space(1) _     & "xmlns : o = 'urn: schemas -microsoft - com: office: office'" 

You can then use the following code to retrieve your properties:

 Set oNodeList = oXMLDOM.selectNodes("d:propstat/d:prop/o:Title") 

You can also use SetProperty to specify using XPath syntax over the default XSL Transformations (XSLT) syntax in your node selection, if that is what you prefer. The following code does this:

 oXMLDOM.SetProperty("SelectionLanguage", "XPath") 



Programming Microsoft Outlook and Microsoft Exchange 2003
Programming MicrosoftВ® OutlookВ® and Microsoft Exchange 2003, Third Edition (Pro-Developer)
ISBN: 0735614644
EAN: 2147483647
Year: 2003
Pages: 227
Authors: Thomas Rizzo

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net