MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

assignment doesn't work with xmlDocument object

  Asked By: Bastet    Date: Oct 10    Category: MS Office    Views: 1766

This one is strange.
The following sub is quite simple:

Private Sub YahooSearch
' Sub uses Yahoo REST based API
' Requires reference to Microsoft XML object library.
Dim xdoc As New DOMDocument
Dim num As Long
Dim search as string
' Create the search request
= "api.search.yahoo.com/WebSearchService/V1/webSearch" & _
"?appid=my_id" & _
"&query=" & "Ephraim Sevela we were not like other people" & _
xdoc.Load search

'observation of xdoc in the Watch Window shows Yahoo!
'responded as expected

num = xdoc.childNodes.length '#### this is the problem line ####

End Sub ' #### this is were my breakpoint is located ####

I located a breakpoint at the last line. Using the Watch Window I
examined both sides of the problem line.
The value of xdoc.childNodes.length is 3, as indicated in the Watch
The value of num is 0.
The assignment operator "=" does not work. I do not get any error
message, or any other indication anything is wrong.
Other attempts I made to get other values from the XML document, such
as strings an objects, failed in a similar way. Strings remained
equal to the null string, objects I tried to set remained as

I have "Microsoft XML, version 2.0" reference checked.



1 Answer Found

Answer #1    Answered By: Ella Brown     Answered On: Oct 10

Found the culprit!
domDocument.load can work  either asynchronously or synchronously. For
some reason, asynchronous work is the default.
The following line, inserted between the construction and the .load
operation eliminates the problem:

xdoc.async = false

Wonders of real-time processing!

Didn't find what you were looking for? Find more on assignment doesn't work with xmlDocument object Or get search suggestion and latest updates.