XMLWriter语法问题

时间:2010-03-09 08:38:49

标签: asp.net xml web-services syntax

我正在尝试创建一个允许用户输入信息的asp.net Web表单,然后将这些信息通过XMLwriter发送到Web服务。

这是xml的片段,因为它应该输出;

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
 <soap:Body xmlns:ns1="http://its/foo.wsdl">

我试图通过代码来操纵它;

xml.WriteStartElement("soap", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/")     
xml.WriteAttributeString("xmlns", "ns1", "http://its/foo.wsdl")

但是我收到了这个错误:

The 'xmlns' attribute is bound to the reserved namespace 'http://www.w3.org/2000/xmlns/'.

谁能告诉我我做错了什么?

感谢。

2 个答案:

答案 0 :(得分:1)

using (var writer = XmlWriter.Create(Console.Out))
{
    writer.WriteStartElement("soap", "Envelope", "http://schemas.xmlsoap.org/soap/envelope/");
    writer.WriteStartElement("soap", "Body", null);
    writer.WriteAttributeString("xmlns", "ns1", null, "http://its/foo.wsdl");
    // ... add other tags
    writer.WriteEndElement();
    writer.WriteEndElement();
}

答案 1 :(得分:0)

简而言之,'xmlns'“属性”不是真正的属性。它们是名称空间声明。您不需要生成它们。必要时,它们将作为将内容生成到不同XML名称空间的一部分生成。

相关问题