2014-10-28 77 views
1

我必须构建具有SOAP信封,像这样的XML文档的SOAP信封:构建使用LINQ to XML

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

认为SOAP-ENV也是一个的XElement,所以尝试这样的:

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")); 

给出了这样的错误:

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

任何线索?

在此先感谢。

回答

3

试试这个

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")); 
+0

感谢您的时间和回答 – Codehelp 2014-10-28 08:15:04

+0

欢迎您。 – kennyzx 2014-10-28 08:15:38