views:

451

answers:

3

Hi:

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--

Thanks!!

+3  A: 

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();
Marc Gravell
alot of code based on XmlWriter, so not an option at the moment...
Scott Kramer
cool, looks good
Scott Kramer
+5  A: 

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();
baretta
wow, i learn so much here!! I'm moving along now... amazon accepted the feed... touchy api!!
Scott Kramer
A: 
Richard