Friday July 11, 2008 In a previous post I have presented the details of the VBScript script used to interact with a JMX application in which a Web Services Connector was deployed.
In order to deal with XML namespaces, I wrote a really horrible function based on the knowledge of the namespace prefix name computation. Something that I presented as a very bad way, caused by my lack of expertise in VBScript.
Since this previous post, I have written a bunch of scripts and dived into some VBScript librairies details. I have found the right way to process XML and deal with Namespaces. This is done thanks to XPATH usage. By setting a set of properties on the object returned by CreateObject("Microsoft.XMLDOM"), you can inject prefix/namespace associations. These associations are then usable when selecting XML nodes.
set reply = ...
Dim objXMLDoc
set objXMLDoc = CreateObject("Microsoft.XMLDOM")
' Make the reply to be loaded synchronously
objXMLDoc.async = False
' Load the reply
objXMLDoc.loadXML(reply)
' Make XPath the selection dialect
objXMLDoc.setProperty "SelectionLanguage", "XPath"
' Associate "wsen" prefix to WS-Enumeration namespace.
objXMLDoc.setProperty "SelectionNamespaces", "xmlns:wsen='http://schemas.xmlsoap.org/ws/2004/09/enumeration'"
' There is a single enumeration node, selectSingleNode returns the first one.
Dim node
set node = objXMLDoc.selectSingleNode("//wsen:EnumerationContext")
' node.text contains the enumeration context value
dim enumContext
set enumContext = node.text
set reply = ...
dim replyXml
set replyXml= CreateObject("Microsoft.XMLDOM")
replyXml.async = False
replyXml.loadXML(reply)
' Make XPath the selection dialect
replyXml.setProperty "SelectionLanguage", "XPath"
' Associate "jmx" prefix to JMX Web Services Connector namespace.
replyXml.setProperty "SelectionNamespaces", "xmlns:jmx='http://jsr262.dev.java.net/jmxconnector'"
' Select all the Notification Message nodes text values
set msgList = replyXml.selectNodes("//jmx:TargetedNotification/jmx:Message/text()")
' Display the Messages
for i = 0 To (msgList.length - 1)
set msg = msgList(i)
' Display the notification message
WScript.echo "Notification : " & msg
next
Hope this help.
Jean-François
Posted by jeanfrancoisdenise ( Jul 11 2008, 03:40:59 PM GMT+02:00 ) Permalink
A. Sundararajan
Alan Bateman
Daniel Fuchs
Éamonn McManus
Joël Féraud
Mandy Chung
Luis-Miguel Alventosa