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
Sebastian_MaresAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sebastian_MaresAuthor Commented:
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.
0
Carl TawnSystems and Integration DeveloperCommented:
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.
0
Carl TawnSystems and Integration DeveloperCommented:
It appears to be due to the default namespace on the document.
If you setup an alias for the default namespace, then you should be able to use that for selecting nodes.

Add the line:
 
        objXMLParser.setProperty "SelectionNamespaces", "xmlns:x='http://webservices.amazon.com/AWSECommerceService/2004-11-10'"

After the line:

        objXMLParser.validateOnParse = True

Then change:

        Set objXMLSubChild = objXMLChild.SelectSingleNode("LargeImage")

To:

       Set objXMLSubChild = objXMLChild.SelectSingleNode("x:LargeImage")


This should then allow you to select the nodes properly using the 'x:' prefix.

Hope this helps.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Sebastian_MaresAuthor Commented:
0
Sebastian_MaresAuthor Commented:
Do you know if the URL changed?
0
Carl TawnSystems and Integration DeveloperCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.