6

This feed (snippit of it) needs to look exactly like this:

<AmazonEnvelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xsi:noNamespaceSchemaLocation="amzn-envelope.xsd">

what do I add to this C# code to add that extra xmlns, xsi junk:

writer.WriteStartDocument();
writer.WriteStartElement("AmazonEnvelope");

this feed is rejected without it--

2
  • 1
    You haven't mentioned which programming language you're using. One assumes C# because WriteStartDocument is a method on XmlWriter, but that's not a guarantee.
    – Randolpho
    May 29, 2009 at 21:01
  • It says "C#" in the middle of the line just below the XML fragment.....
    – marc_s
    May 29, 2009 at 21:11

2 Answers 2

8

Try this:

writer.WriteStartElement("AmazonEnvelope");
writer.WriteAttributeString(
  "xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString(
  "xsi", "noNamespaceSchemaLocation", null, "amzn-envelope.xsd");
...
writer.WriteEndElement();
1
  • wow, i learn so much here!! I'm moving along now... amazon accepted the feed... touchy api!! May 29, 2009 at 21:42
5

Is .NET 3.5 an option?

XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance";

string s = new XElement("AmazonEnvelope",
    new XAttribute(XNamespace.Xmlns + "xsi", ns),
    new XAttribute(ns + "noNamespaceSchemaLocation", "amzn-envelope.xsd")
).ToString();

or with XmlWriter:

const string ns = "http://www.w3.org/2001/XMLSchema-instance";
writer.WriteStartDocument();
writer.WriteStartElement("AmazonEnvelope");
writer.WriteAttributeString("xmlns", "xsi", "", ns);
writer.WriteAttributeString("xsi", "noNamespaceSchemaLocation",
      ns, "mzn-envelope.xsd");
writer.WriteEndDocument();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.