0

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.

chris c
  • 321
  • 2
  • 14
  • Does this answer your question? [Adding multiple namespace declarations in XmlWriter](https://stackoverflow.com/q/1905204/3744182). – dbc Jan 17 '18 at 19:19
  • @dbc thanks for the help but I don't think this will help. I need to output this `` which doesn't look like multiple namespaces – chris c Jan 17 '18 at 21:24
  • Actually that did help @dbc thanks for your help :D – chris c Jan 17 '18 at 22:03

1 Answers1

1

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

chris c
  • 321
  • 2
  • 14