I am having a problem with a XML deserialization from Walmart Items API.
This is code that i am using to deserialize the response. Does anyone have idea on how to deserialize the properties without namespace? I tried to set default namespace to http://walmart.com but that did not work.
This is the code.
var resp = await client.GetAsync(fullurl);
var serializer = new XmlSerializer(typeof(T));
string xmlstr = await resp.Content.ReadAsStringAsync();
using (TextReader reader = new StringReader(xmlstr))
{
T itemResps = (T)serializer.Deserialize(reader);
}
The properties under ns:price (currenty , amount) have no namespace while all other elements have namespace.
This is a response from the walmart api server:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:ItemResponses xmlns:ns2="http://walmart.com/">
<ns2:ItemResponse>
<ns2:mart>WALMART_US</ns2:mart>
<ns2:sku>WALSKU000</ns2:sku>
<ns2:wpid>FFOEKJFJSI</ns2:wpid>
<ns2:upc>887276146249</ns2:upc>
<ns2:gtin>00887276146249</ns2:gtin>
<ns2:productName>Samsung Galaxy Tab E Lite 7" 8GB Tablet - Android 4.4 KitKat</ns2:productName>
<ns2:productType>Tablet Computers</ns2:productType>
<ns2:price>
<currency>USD</currency>
<amount>107.00</amount>
</ns2:price>
<ns2:publishedStatus>SYSTEM_PROBLEM</ns2:publishedStatus>
</ns2:ItemResponse>
<ns2:ItemResponse>
<ns2:mart>WALMART_US</ns2:mart>
<ns2:sku>WALSKU001</ns2:sku>
<ns2:wpid>XDHEUHFIHEE</ns2:wpid>
<ns2:upc>045496590086</ns2:upc>
<ns2:gtin>00045496590086</ns2:gtin>
<ns2:productName>Nintendo Switch Gaming Console with Gray Joy-Con</ns2:productName>
<ns2:productType>Video Game Consoles</ns2:productType>
<ns2:price>
<currency>USD</currency>
<amount>399.99</amount>
</ns2:price>
<ns2:publishedStatus>UNPUBLISHED</ns2:publishedStatus>
</ns2:ItemResponse>
</ns2:ItemResponses>
This is the Sample response from walmart item API. It does not contain namespace on all elements. I think it used to come like this. but it does not come anymore.
<?xml version="1.0" encoding="UTF-8"?>
<ItemResponses xmlns:ns2="http://walmart.com/">
<ItemResponse>
<mart>WALMART_US</mart>
<sku>379third908</sku>
<gtin>00313159099947</gtin>
<productName>Carex Soft Grip Folding Cane - Black Walking Cane</productName>
<productType>Walking Canes</productType>
<price>
<currency>USD</currency>
<amount>13.27</amount>
</price>
<publishedStatus>IN_PROGRESS</publishedStatus>
</ItemResponse>
<ItemResponse>
<mart>WALMART_US</mart>
<sku>prodtest1571</sku>
<upc>889296686590</upc>
<gtin>00889296686590</gtin>
<productName>REFURBISHED: HP 250 G3 15.6" Notebook, Intel 4th Gen i3, 4GB RAM, 500GB HDD, Win 8.1, M5G69UT#ABA</productName>
<productType>RAM Memory</productType>
<price>
<currency>USD</currency>
<amount>329.99</amount>
</price>
<publishedStatus>PUBLISHED</publishedStatus>
</ItemResponse>
</ItemResponses>