2014-10-28 72 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