开发者

XMLWriter syntax problems

I am trying to create an asp.ne开发者_开发问答t web form that allows a user to enter information, then have this information sent via an XMLwriter to a web service.

Here is a snippet of the xml as it should be outputted;

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

I try to manipulate this via code;

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

But I get this error:

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

Can anyone tell me what I am doing wrong?

Thanks.


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


Briefly, the 'xmlns' "attributes" are not real attributes. They are namespace declarations. You do not need to generate them. They will be generated, as necessary, as part of the generation of your content into different XML namespaces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜