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.DOMDo cument.4.0 ")
objXMLParser.ASync = False
objXMLParser.PreserveWhite Space = False
objXMLParser.ResolveExtern als = False
objXMLParser.ValidateOnPar se = True
Then, later in the code, I use:
Set objXMLChild = Nothing
Set objXMLChild = objXMLItems.ChildNodes.Ite m(lngCount er)
If Not objXMLChild Is Nothing Then
Select Case objXMLChild.NodeName
Case "TotalResults"
lngTotalNumberOfResults = CLng(objXMLChild.Text)
Case "Item"
Set objXMLSubChild = Nothing
Set objXMLSubChild = objXMLChild.SelectSingleNo de("LargeI mage")
If Not objXMLSubChild Is Nothing Then
Set objXMLLargeImageURL = Nothing
Set objXMLLargeImageURL = objXMLSubChild.SelectSingl eNode("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.DOMDo cument.4.0 ")
to
Set objXMLParser = CreateObject("MSXML.DOMDoc ument")
everything works as expected. Any idea what could be wrong?
Regards,
Sebastian
Currently, I am experiencing some problems with selecting nodes.
I am invoking the XML parser using:
Set objXMLParser = CreateObject("Msxml2.DOMDo
objXMLParser.ASync = False
objXMLParser.PreserveWhite
objXMLParser.ResolveExtern
objXMLParser.ValidateOnPar
Then, later in the code, I use:
Set objXMLChild = Nothing
Set objXMLChild = objXMLItems.ChildNodes.Ite
If Not objXMLChild Is Nothing Then
Select Case objXMLChild.NodeName
Case "TotalResults"
lngTotalNumberOfResults = CLng(objXMLChild.Text)
Case "Item"
Set objXMLSubChild = Nothing
Set objXMLSubChild = objXMLChild.SelectSingleNo
If Not objXMLSubChild Is Nothing Then
Set objXMLLargeImageURL = Nothing
Set objXMLLargeImageURL = objXMLSubChild.SelectSingl
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.DOMDo
to
Set objXMLParser = CreateObject("MSXML.DOMDoc
everything works as expected. Any idea what could be wrong?
Regards,
Sebastian
I think its something to do with the namespace.
If you change then line:
Set objXMLSubChild = objXMLChild.SelectSingleNo de("LargeI mage")
To:
Set objXMLSubChild = objXMLChild.SelectSingleNo de("*[loca l-name()=' LargeImage ']")
Then it should work OK.
If you change then line:
Set objXMLSubChild = objXMLChild.SelectSingleNo
To:
Set objXMLSubChild = objXMLChild.SelectSingleNo
Then it should work OK.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
"http://webservices.amazon.com/AWSECommerceService/2004-11-10" returns a 404.
ASKER
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.
Hope this clears things up a bit. Namespaces are a bit odd until you get used to them.
ASKER
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.