I'm working on a VBA script to get data from a xml document. I need help to modify my XPath code to search for a partial string instead of the whole one. This is my current expression:
xmlhttpResponse.SelectNodes("/CharacteristicList/Characteristic[Name='ZCOMP_A_03']
/ComplexValueList/ValueItem/Value").Item(0).text
What I would like to do is something like this [Name='ZCOMP_A_'], but it doesn't seems to exist or to work like this. I saw some codes with starts-with and contains, but I would like to use a XPath similar with the one already used (if possible).
This is part of the XML code.
<CharacteristicList>
<Characteristic>
<Name>ZCOMP_A_03</Name>
<ValueList>
<ValueItem>
<Value>10.50</Value>
Update 1! I made some changes according to kjhughes, but I'm getting a "Unknown method" error. This is the updated code:
Dim xmlhttpRequest As New MSXML2.xmlhttp
Dim xmlhttpResponse As New MSXML2.DOMDocument
xmlhttpResponse.setProperty "SelectionLanguage", "XPath"
Envelope = Envelope & "</soapenv:Envelope>"
xmlhttpRequest.Open "POST", "http://website.xyz"
xmlhttpRequest.setRequestHeader "Content-Type", "text/xml;charset=UTF-8"
xmlhttpRequest.setRequestHeader "SOAPAction", "http://website2.xyz"
xmlhttpRequest.send Envelope
Set xmlhttpResponse = xmlhttpRequest.responseXML
'Lenght_1 = xmlhttpResponse.SelectNodes("//Characteristic[Name='ZCOMP_A_03']/ComplexValueList/ValueItem/Value").Item(0).text Previous version
Lenght_2 = xmlhttpResponse.SelectNodes("//Characteristic[starts-with(Name,'ZCOMP_A_')]/ComplexValueList/ValueItem/Value").Item(0).text
SelectNodes("//Characteristic//Name[contains(.,'ZCOMP_A_')]")(0).Textthis expression should bring you the desired results.