使用LINQ to XML构建SOAP信封

3

我需要构建一个XML文档,其中包含一个如下的SOAP信封:

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

出现以下错误:

无法在名称中包含字符“:”,十六进制值为0x3A。

有什么线索吗?

提前致谢。

1个回答

4

试试这个

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接