XMLHTTP wait for webpage response and obtain xml element ID

Trebor8484

Board Regular
Joined
Oct 27, 2018
Messages
69
Office Version
  1. 2013
Platform
  1. Windows
Hi,

Does anyone know how I can ammend the below code to wait for the web page to finish loading please?

Also, I am trying to obtain the book id, but not sure how to accomplish this.

Rich (BB code):
<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>

VBA Code:
Sub xmlParse()
    
    Dim oXMLHTTP As Object
    Dim sPageHTML As String
    Dim sURL As String
    Dim XmlMapResponse As String
    Dim strXML As String
    Dim XDoc As MSXML2.DOMDocument60
    Dim xNode As MSXML2.IXMLDOMNode

    sURL = "https://gist.githubusercontent.com/Ram-N/5189462/raw/46db0b43ad7bf9cbd32a8932f3ab981bd4b4da7c/books.xml"

    Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
    
    oXMLHTTP.Open "GET", sURL, False
    oXMLHTTP.send
    XmlMapResponse = oXMLHTTP.responseText

    strXML = XmlMapResponse

    Set XDoc = New MSXML2.DOMDocument60

    If Not XDoc.LoadXML(strXML) Then
        Err.Raise XDoc.parseError.ErrorCode, , XDoc.parseError.reason
    End If

'   Selects the author element for the first book element
    Set xNode = XDoc.SelectSingleNode("catalog/book[1]/author")
    Debug.Print xNode.Text & vbNewLine

'   Loop through each title element that is the child of the book element
    For Each xNode In XDoc.SelectNodes("catalog/book/title")
        Debug.Print xNode.Text
    Next xNode

End Sub

Thanks
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Hi,

Does anyone know how I can ammend the below code to wait for the web page to finish loading please?

Also, I am trying to obtain the book id, but not sure how to accomplish this.

Rich (BB code):
<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications
      with XML.</description>
   </book>

VBA Code:
Sub xmlParse()
   
    Dim oXMLHTTP As Object
    Dim sPageHTML As String
    Dim sURL As String
    Dim XmlMapResponse As String
    Dim strXML As String
    Dim XDoc As MSXML2.DOMDocument60
    Dim xNode As MSXML2.IXMLDOMNode

    sURL = "https://gist.githubusercontent.com/Ram-N/5189462/raw/46db0b43ad7bf9cbd32a8932f3ab981bd4b4da7c/books.xml"

    Set oXMLHTTP = CreateObject("MSXML2.ServerXMLHTTP")
   
    oXMLHTTP.Open "GET", sURL, False
    oXMLHTTP.send
    XmlMapResponse = oXMLHTTP.responseText

    strXML = XmlMapResponse

    Set XDoc = New MSXML2.DOMDocument60

    If Not XDoc.LoadXML(strXML) Then
        Err.Raise XDoc.parseError.ErrorCode, , XDoc.parseError.reason
    End If

'   Selects the author element for the first book element
    Set xNode = XDoc.SelectSingleNode("catalog/book[1]/author")
    Debug.Print xNode.Text & vbNewLine

'   Loop through each title element that is the child of the book element
    For Each xNode In XDoc.SelectNodes("catalog/book/title")
        Debug.Print xNode.Text
    Next xNode

End Sub

Thanks

Hi, anyone please?
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top