0

I'm guessing this is pretty straightforward but I'm not well versed in handling xml data.

I have some vbscript code that processes xml data from a third party in this format.

<data>
    <thing1>some thing</thing1>
    <thing2>some other thing</thing2>
    <parameter>
        <parameterName>customThing1</paramterName>
        <parameterValue>this is the data i want</parameterValue>
    </parameter>
</data>

Previously, all data came in like thing1 or thing2. Now we have had to add a custom field to the data, and the third party is sending it in this 'parameter' format.

I get the old data like so: (objXmlRequest is an MSXML2.DomDocument object)

thing1 = objXmlRequest.documentElement.selectSingleNode("thing1").firstChild.nodeValue

Now I need to get the value for customThing1, but I don't want to just pull 'parameterValue' because if we add another custom field in the future that will be a problem. So I need to make sure I'm getting paramterValue where parameterName = customThing1. How would I do that?

1 Answer 1

1

Based on this: Find a parameter with a customThing1 parameterName and access its parameterValue:

Dim objMSXML : Set objMSXML = CreateObject("Msxml2.DOMDocument")
objMSXML.setProperty "SelectionLanguage", "XPath"
objMSXML.async = False
objMSXML.load ".\38512955.xml"

If 0 = objMSXML.parseError Then
   Dim sXPath : sXPath  = "/data/parameter[parameterName=""customThing1""]/parameterValue"
   Dim ndX    : Set ndX = objMSXML.selectSingleNode(sXPath)
   If ndX Is Nothing Then
      WScript.Echo sXPath, "failed"
   Else
      WScript.Echo ndX.tagName, ndX.text
   End If
Else
   WScript.Echo objMSXML.parseError.reason
End If

output:

cscript 38512955.vbs
parameterValue this is the data i want
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.