?
Solved

How to read an XML return string from within VBScript?

Posted on 2001-07-17
5
Medium Priority
?
4,092 Views
Last Modified: 2012-06-27
From within a .vbs program, I call an API which returns to me as a return code an XML string.

There are only certain 'element' values that I need to retrieve from the string, and I know there must be a better way of doing it than manually searching through a string of characters for what I want.

Here's a simplified version of my XML string:

<RETURN_CODE>
      <SUMMARY>
            <NUMBER_PROCESSED> 4 </NUMBER_PROCESSED>
            <NUMBER_REQUESTED> 4 </NUMBER_REQUESTED>
            </ERROR_CODE>
      </SUMMARY>
</RETURN_CODE>

So I currently have this XML return code assigned to a variable, as follows:


Dim object
Dim returnCode

returnCode = object.methodThatReturnsXMLResult()


Now, can I somehow put the contents of 'returnCode' (the XML string above) into an XML DOM and then query it for the values of, lets say, <NUMBER_PROCESSED> and/or <NUMBER_REQUESTED> ?

Code/syntax to do this is much appreciated!

Thanks!
0
Comment
Question by:BrianAbrahamson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6291599
>>From within a .vbs program, I call an API which returns to me as a return code an XML string

what API function are you using?  is it truly an exported function of a dynamic link library?
0
 

Author Comment

by:BrianAbrahamson
ID: 6291633
I create an object from the instantiation of a DLL - the DLL is for a 3rd party product we have purchased.  I then call a method of that object, passing it the appropriate parameters.  That method has a return value, and the return value is an XML string.  

i.e.

returnCode = object.theMethodThatReturnsXML(param 1, param2)

If we were to do a 'msgbox' on the variable 'returnCode' -
i.e. msgbox(returnCode)

the result would literally be:
 "<RETURN_CODE><SUMMARY><NUMBER_PROCESSED>4</NUMBER_PROCESSED>....."   - you get the picture...  

If I need the value between the <NUMBER_PROCESSED> tags, I would like to be able to access the nodes/elements of this XML string via the XMLDOM or something instead of parsing through it manually to match on substrings or something.  

Please note that my example is simplified, so parsing through looking for a substring and then grabbing the value '4' or something is not feasible.

Thanks.
0
 

Author Comment

by:BrianAbrahamson
ID: 6291677
I create an object from the instantiation of a DLL - the DLL is for a 3rd party product we have purchased.  I then call a method of that object, passing it the appropriate parameters.  That method has a return value, and the return value is an XML string.  

i.e.

returnCode = object.theMethodThatReturnsXML(param 1, param2)

If we were to do a 'msgbox' on the variable 'returnCode' -
i.e. msgbox(returnCode)

the result would literally be:
 "<RETURN_CODE><SUMMARY><NUMBER_PROCESSED>4</NUMBER_PROCESSED>....."   - you get the picture...  

If I need the value between the <NUMBER_PROCESSED> tags, I would like to be able to access the nodes/elements of this XML string via the XMLDOM or something instead of parsing through it manually to match on substrings or something.  

Please note that my example is simplified, so parsing through looking for a substring and then grabbing the value '4' or something is not feasible.

Thanks.
0
 
LVL 5

Accepted Solution

by:
mattyk earned 200 total points
ID: 6291681
This hsould give you the syntax you're looking for:

Dim xmlDoc
Set xmlDoc = WScript.CreateObject("Microsoft.XMLDOM")
xmlDoc.loadxml(object.methodThatReturnsXMLResult())


Dim objNumReqs
Dim objNumReq
Set objNumReqs = xmlDoc.getElementsByTagName("NUMBER_REQUESTED")

for each objNumReq in objNumReqs
     msgbox objNumReq.text
Next

-matty
0
 

Expert Comment

by:Yogi012398
ID: 7239152
Instead of using the getElementsByTagName, try selectSingleNode. By adding two forward slashes in front of the node, it will search the whole xml doc for the node and retrieve the value.

Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.setProperty "ServerXMLHTTP", true
xml.load sPath 'Path of xml doc
sValue = xml.selectSingleNode("//NUMBER_PROCESSED").text

-Yogi
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question