I'm wanting to use VBA in MS Access to read in some XML, but I'm getting a 'Object variable or With block reference not set' error when parsing this XML...
<?xml version="1.0"?>
<GetCompetitivePricingForASINResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<GetCompetitivePricingForASINResult ASIN="B002L7HJAA" status="Success">
<Product
xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01"
xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>A1F83G8C2ARO7P</MarketplaceId>
<ASIN>B002L7HJAA</ASIN>
</MarketplaceASIN>
</Identifiers>
<CompetitivePricing>
<CompetitivePrices>
<CompetitivePrice belongsToRequester="false" condition="New" subcondition="New">
<CompetitivePriceId>1</CompetitivePriceId>
<Price>
<LandedPrice>
<CurrencyCode>GBP</CurrencyCode>
<Amount>14.45</Amount>
</LandedPrice>
</Price>
</CompetitivePrice>
</CompetitivePrices>
</CompetitivePricing>
</Product>
</GetCompetitivePricingForASINResult>
</GetCompetitivePricingForASINResponse>
using this code...
Public Function READXML()
Dim objXMLNode1 As MSXML2.IXMLDOMNodeList
Set objXMLDoc = New MSXML2.DOMDocument60
objXMLDoc.loadXML ("C:\Users\LW\Desktop\formatted.xml")
XmlNamespaces = "xmlns:ns2='http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd' xmlns:ns1='http://mws.amazonservices.com/schema/Products/2011-10-01'"
objXMLDoc.SetProperty "SelectionNamespaces", XmlNamespaces
Set objXMLNode1 = objXMLDoc.selectSingleNode("//ns2:Price/ns2:LandedPrice/ns2:Amount")
MsgBox objXMLNode1(0).text
End Function
As you can see, I seek to extract the XML value (showing in the XML as 14.45)
I've spent a good while googling this to no avail, but settled on the above code aftr reading this 'SelectSingleNode' XPath query from XML with multiple Namespaces
Any ideas why I'm getting the error?