Pergunta

Este feed (snippit dele) precisa de olhar exatamente como isto:

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

O que posso adicionar a este código C # para acrescentar que xmlns extras, junk xsi:

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

este feed é rejeitada sem ele -

Nenhuma solução correta

Outras dicas

Tente isto:

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();

é NET 3.5 é uma opção?

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();

ou com 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();
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top