peskywinnets
Registered User.
- Local time
- Today, 15:20
- Joined
- Feb 4, 2014
- Messages
- 578
Hiya,
I've got the most simple of XML reading in VBA going on, here's the code...
& here's the XML (for simplicity I'm copying the XML into a file called test.xml, but in reality it comes from an http request)...
It all works as I want (i.e. the text between the <amount> </amount> tags is extracted as 8.61 correctly, however, I've actually had to modify the original XML, because the <product> line is actually pulled back from the originating source as this...
with that long line in the <product> opening tag, my code doesn't extract the required data, so clearly it's not happy & only works if the tag has just <product> in it.
So I need a way of changing this text...
to this....
Alternatively it looks like the text that my code is barfing over, actually may be of use....it appears to be a link to an .xsd .....perhaps I need to use that?)
I've got the most simple of XML reading in VBA going on, here's the code...
Code:
Public Function READXML() 'Reference Microsoft XML 6.0 required
Dim testDOM As DOMDocument60
Dim objRoot As IXMLDOMElement
Dim strMsg As String
Set testDOM = New DOMDocument60
testDOM.resolveExternals = False
testDOM.validateOnParse = False
testDOM.Load ("C:\test.xml")
Set objRoot = testDOM.documentElement
txtPrice = objRoot.selectSingleNode("/Product/CompetitivePricing/CompetitivePrices/CompetitivePrice/Price/LandedPrice/Amount").text
Debug.Print txtPrice
End Function
& here's the XML (for simplicity I'm copying the XML into a file called test.xml, but in reality it comes from an http request)...
Code:
<Product>
<Identifiers>
<MarketplaceASIN>
<MarketplaceId>A1F83G8C2ARO8P</MarketplaceId>
<ASIN>B005J38BX5</ASIN>
</MarketplaceASIN>
</Identifiers>
<CompetitivePricing>
<CompetitivePrices>
<CompetitivePrice belongsToRequester="true" condition="New" subcondition="New">
<CompetitivePriceId>1</CompetitivePriceId>
<Price>
<LandedPrice>
<CurrencyCode>GBP</CurrencyCode>
<Amount>8.61</Amount>
</LandedPrice>
<ListingPrice>
<CurrencyCode>GBP</CurrencyCode>
<Amount>8.61</Amount>
</ListingPrice>
<Shipping>
<CurrencyCode>GBP</CurrencyCode>
<Amount>0.00</Amount>
</Shipping>
</Price>
</CompetitivePrice>
</CompetitivePrices>
<NumberOfOfferListings>
<OfferListingCount condition="New">10</OfferListingCount>
<OfferListingCount condition="Any">10</OfferListingCount>
</NumberOfOfferListings>
</CompetitivePricing>
<SalesRankings>
<SalesRank>
<ProductCategoryId>ce_display_on_website</ProductCategoryId>
<Rank>25388</Rank>
</SalesRank>
<SalesRank>
<ProductCategoryId>1939024031</ProductCategoryId>
<Rank>22</Rank>
</SalesRank>
</SalesRankings>
</Product>
It all works as I want (i.e. the text between the <amount> </amount> tags is extracted as 8.61 correctly, however, I've actually had to modify the original XML, because the <product> line is actually pulled back from the originating source as this...
Code:
<Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
with that long line in the <product> opening tag, my code doesn't extract the required data, so clearly it's not happy & only works if the tag has just <product> in it.
So I need a way of changing this text...
Code:
<Product xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01" xmlns:ns2="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">
to this....
Code:
<Product>
Alternatively it looks like the text that my code is barfing over, actually may be of use....it appears to be a link to an .xsd .....perhaps I need to use that?)
Last edited: