开发者

C#: Explicit Namespace not Appearing in Generated XML

开发者 https://www.devze.com 2022-12-15 16:12 出处:网络
Given the following C# code to generate an XML file: XmlDocument requestXML = new XmlDocument(); XmlDeclaration declaration = requestXML.CreateXmlDeclaration( \"1.0\", \"utf-8\", null );

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

精彩评论

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