Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to read an XML return string from within VBScript?

Posted on 2001-07-17
5
Medium Priority
?
4,309 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
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

963 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