开发者

C#: Explicit Namespace not Appearing in Generated XML

Given the following C# code to generate an XML file:

    XmlDocument requestXML = new XmlDocument();

    XmlDeclaration declaration = requestXML.CreateXmlDeclaration( "1.0", "utf-8", null );
    requestXML.AppendChild( declaration );

    XmlElement soapEnvelope = requestXML.CreateElement( "soap:Envelope" );

    soapEnvelope.SetAttribute( "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" );
    soapEnvelope.SetAttribute( "xmlns:xsd", "http://www.w3.org/2001/XMLSchema" );
    soapEnvelope.SetAttribut开发者_如何学JAVAe( "xmlns:soap", "http://schemas.xmlsoap.org/soap/envelope/" );

The XML I'm seeing in requestXML.OuterXML shows

<Envelope ...>

Rather than

<soap:Envelope ...>

as I would expect. What am I doing wrong?


Maybe you could try the CreateElement overload that takes a namespace uri as parameter #2.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜