全部,我想创建一个肥皂信封xml文件,例如.
<soap:Envelope soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding" xmlns:soap="http://www.w3.org/2001/12/soap-envelope"></soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
我正在使用System.Xml.Linq这样做但我无法弄清楚如何将属性添加soap到该encodingStyle属性.
到目前为止,我有这个:
XNamespace ns = XNamespace.Get("http://www.w3.org/2001/12/soap-envelope");
XAttribute prefix = new XAttribute(XNamespace.Xmlns + "soap", ns);
XAttribute encoding = new XAttribute("encodingStyle", "http://www.w3.org/2001/12/soap-encoding");
XElement envelope = new XElement(ns + "Envelope", prefix, encoding);
Run Code Online (Sandbox Code Playgroud)
这给了我
<soap:Envelope encodingStyle="http://www.w3.org/2001/12/soap-encoding" xmlns:soap="http://www.w3.org/2001/12/soap-envelope"></soap:Envelope>
Run Code Online (Sandbox Code Playgroud)
您用来XAttribute为元素添加前缀,我可以XAttribute用来添加前缀XAttribute吗?
谢谢,P
Bra*_*ger 11
在创建'encodingStyle'XAttribute时(通过使用ns + "encodingStyle")指定命名空间:
XAttribute encoding = new XAttribute(ns + "encodingStyle", "http://www.w3.org/2001/12/soap-encoding");
Run Code Online (Sandbox Code Playgroud)
在两个参数XAttribute构造函数需要一个XName作为第一个参数.这可以从一个隐式构造string(如在您的问题的代码),或通过"加入"直接在string到XNamespace来创建XName(如上).
| 归档时间: |
|
| 查看次数: |
8489 次 |
| 最近记录: |