Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top