views:

93

answers:

1

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.SetAttribute( "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?

+2  A: 

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

klausbyskov
Well, that was embarassingly easy!
Bob Kaufman