Как мне установить префикс пространства имен для XAttribute в .NET?

Все, I want to create a soap envelope xml document eg.

<soap:Envelope soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding" xmlns:soap="http://www.w3.org/2001/12/soap-envelope"></soap:Envelope>

I am using System.Xml.Linq to do this but I cannot figure out how to add the soap prefix to the encodingStyle attribute.

So far, I have this:

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

which gives me

<soap:Envelope encodingStyle="http://www.w3.org/2001/12/soap-encoding" xmlns:soap="http://www.w3.org/2001/12/soap-envelope"></soap:Envelope>

You use XAttribute to add a prefix to an element, can I use XAttribute to add a prefix to an XAttribute??!

thanks, P

15
задан Pratik 10 December 2010 в 06:39
поделиться