Codehelp
Codehelp

Reputation: 4777

Constructing a SOAP envelope using LINQ to XML

I have to construct an XML document which has a SOAP envelope like so:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
  <SOAP-ENV:Body>

Thought that SOAP-ENV is also a XElement, so tried like this:

XNamespace soap = "http://schemas.xmlsoap.org/soap/envelope/";
            XElement soapEnvelope = new XElement(soap + "SOAP-ENV:Envelope",
                                new XAttribute(XNamespace.Xmlns + "xmlns:SOAP-ENV", soap.NamespaceName),
                                new XElement("SOAP-ENV:Body"));

gives this error:

The ':' character, hexadecimal value 0x3A, cannot be included in a name.

Any clues?

Thanks in advance.

Upvotes: 3

Views: 2333

Answers (1)

kennyzx
kennyzx

Reputation: 13003

Try this

XNamespace soap = "http://schemas.xmlsoap.org/soap/envelope/";

XElement element = new XElement(soap + "Envelope", 
    new XAttribute(XNamespace.Xmlns + "SOAP-ENV", soap),
    new XElement(soap + "Body")); 

Upvotes: 4

Related Questions