我正在尝试创建一个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/'.有人能告诉我我哪里做错了吗?
谢谢。
发布于 2010-03-09 16:57:50
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();
}发布于 2010-03-09 16:43:46
简而言之,'xmlns‘“属性”不是真正的属性。它们是命名空间声明。您不需要生成它们。它们将在必要时生成,作为将内容生成到不同XML名称空间中的一部分。
https://stackoverflow.com/questions/2407593
复制相似问题