I have the following code to get the response text from an XML page, But it returns everything in the page:

Private Sub Testing()
Dim xmlhttp As New MSXML2.XMLHTTP60, myurl As String
myurl = "http://schemas.xmlsoap.org/soap/envelope/"
xmlhttp.Open "GET", myurl, False
xmlhttp.send
newstring = xmlhttp.responseText
Sheet1.Range("B2") = newstring
End Sub

The URL in myurl is for example only. The actual URL i'm trying to get is in an intranet site. But this has similar structure.

EDIT: the following FIELD tag is not available in the URL above. I used the url as an example to show the type of document.

Let's say there's a tag like below is in the middle of the page:

<FIELD NAME="str2">097cf4a8-2755-4c62-939c-9402e0a4e3e2</FIELD>

How do i get only this "097cf4a8-2755-4c62-939c-9402e0a4e3e2" ? the str2 is unique.

Hope someone could help me.

1 Answers

1
QHarr On Best Solutions

Here is an example using a publicly available document. The principle of selecting by combination of tag and attribute value is shown.

Option Explicit
Public Sub Testing()
    Dim xmlhttp As New MSXML2.XMLHTTP60, myurl As String
    myurl = "http://www.chilkatsoft.com/xml-samples/bookstore.xml"
    xmlhttp.Open "GET", myurl, False
    xmlhttp.send
    Dim xmlDoc As New MSXML2.DOMDocument60
    Set xmlDoc = New MSXML2.DOMDocument60
    xmlDoc.LoadXML xmlhttp.responseText
    Debug.Print xmlDoc.SelectSingleNode("//userComment[@rating=""3""]").Text
End Sub

Source:

data

Output:

out