Link to home
Start Free TrialLog in
Avatar of Sebastian_Mares
Sebastian_Mares

asked on

SelectSingleNode fails with MS XML 4.

Hi!

Currently, I am experiencing some problems with selecting nodes.
I am invoking the XML parser using:

Set objXMLParser = CreateObject("Msxml2.DOMDocument.4.0")

objXMLParser.ASync = False
objXMLParser.PreserveWhiteSpace = False
objXMLParser.ResolveExternals = False
objXMLParser.ValidateOnParse = True



Then, later in the code, I use:

Set objXMLChild = Nothing
Set objXMLChild = objXMLItems.ChildNodes.Item(lngCounter)
           
If Not objXMLChild Is Nothing Then
  Select Case objXMLChild.NodeName
    Case "TotalResults"
      lngTotalNumberOfResults = CLng(objXMLChild.Text)
    Case "Item"

      Set objXMLSubChild = Nothing
      Set objXMLSubChild = objXMLChild.SelectSingleNode("LargeImage")

      If Not objXMLSubChild Is Nothing Then
        Set objXMLLargeImageURL = Nothing
        Set objXMLLargeImageURL = objXMLSubChild.SelectSingleNode("URL")
        If Not (objXMLLargeImageURL Is Nothing) Then
          astrLargeImageURL(1) = objXMLLargeImageURL.Text
        End If
      End If
  End Select
End If



However,

If Not objXMLSubChild Is Nothing Then

always returns false.

If I change the initialization part from

Set objXMLParser = CreateObject("Msxml2.DOMDocument.4.0")

to

Set objXMLParser = CreateObject("MSXML.DOMDocument")

everything works as expected. Any idea what could be wrong?

Regards,
Sebastian
Avatar of Sebastian_Mares
Sebastian_Mares

ASKER

If you need a demo, http://maresweb.org/xml.zip .

When you launch the program as-is, it will tell you that it wasn't able to find any images. If you change the XML initialization to MSXML.DOMDocument, it will download Cover.jpg to the application's folder. The SelectSingleNode part returns True when running XML 2 (or whatever MSXML.DOMDocument is) and False when XML 4 or 3 is used.
Avatar of Carl Tawn
I think its something to do with the namespace.

If you change then line:

    Set objXMLSubChild = objXMLChild.SelectSingleNode("LargeImage")

To:

    Set objXMLSubChild = objXMLChild.SelectSingleNode("*[local-name()='LargeImage']")

Then it should work OK.
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you know if the URL changed?
http://webservices.amazon.com/AWSECommerceService/2004-11-10  <--  This isn't necessarily a valid URL, its simply a namespace.  A namespace is a way of uniquely naming elements from a specific supplier in order to avoid naming conflicts.  A namespace can be anything you want, just so long as it is unique.  A lot of developers will choose a namespace that incorporates their company URL so that it will be unique.

Hope this clears things up a bit. Namespaces are a bit odd until you get used to them.