chris c
chris c

Reputation: 331

C# Creating XML file to send to ebay LMS API

Ok so I'm trying to create an xml file to update inventory items using ebay LMS.

I'm having trouble outputting this part of the feed file:

<ReviseInventoryStatusRequest xmlns="urn:ebay:apis:eBLBaseComponents">

This is the code I have so far:

using (var writer = XmlWriter.Create(stream, settings))
                {
                    writer.WriteStartDocument();
                    writer.WriteStartElement("ReviseInventoryStatusRequest");
                    writer.WriteStartAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
                    writer.WriteEndAttribute();
                    writer.WriteStartElement("RequesterCredentials");
                    writer.WriteElementString("eBayAuthToken", ebayAuthTokenSetting.ToString());
                    writer.WriteEndElement();
                    writer.WriteElementString("Version", "967");
                    writer.WriteElementString("ErrorLanguage", "en_US");
                    writer.WriteElementString("WarningLevel", "High");

                    //int counter = 1;

                    //Add the products to feed which do not have variations
                    foreach (var ep in productsToProcess)
                    {
                        var product = _productService.GetProductById(ep.ProductID);
                        var productStockQuantity = product.GetTotalStockQuantity();

                        if (product.GetTotalStockQuantity() != productStockQuantity) {
                            writer.WriteStartElement("InventoryStatus");
                            writer.WriteElementString("SKU", ep.EbayProductSKU);
                            writer.WriteElementString("ItemID", ep.EbayID);
                            writer.WriteElementString("Quantity", productStockQuantity.ToString());
                            writer.WriteEndElement();

                            //ep.EbayProductStockQuantity = productStockQuantity;
                            //_ebayProductService.UpdateEbayProduct(ep);

                            sendEbayApiRequest = true;
                        }
                    }

                    writer.WriteEndElement(); // ReviseInventoryStatusRequest
                    writer.WriteEndDocument(); // productfeed
                }

I have tried this to output that part of the file:

writer.WriteStartAttribute("xmlns", "urn:ebay:apis:eBLBaseComponents");
writer.WriteEndAttribute();

Have also tried this:

writer.WriteAttributeString("xmlns", null, "urn:ebay:apis:eBLBaseComponents", null);

And other variations of the code snippet above like:

writer.WriteAttributeString(null, "xmlns", null, "urn:ebay:apis:eBLBaseComponents");

Im kind of lost as to how to do this, I have seen some examples but the are not helping.

Anyone can help, thanks.

Upvotes: 0

Views: 232

Answers (1)

chris c
chris c

Reputation: 331

Ok so thanks to the help from @dbc I had to use the following code.

writer.WriteStartElement("ReviseInventoryStatusRequest", "urn:ebay:apis:eBLBaseComponents");

Which outputs

<ReviseInventoryStatusRequest xmlns="urn:ebay:apis:eBLBaseComponents">

Thanks @dbc

Upvotes: 1

Related Questions