How do I set a namespace prefix to an XAttribute in .NET?

后端 未结 3 1770
清歌不尽
清歌不尽 2021-02-19 02:31

All, I want to create a soap envelope xml document eg.



        
3条回答
  •  一向
    一向 (楼主)
    2021-02-19 03:03

    Specify the namespace when you create the 'encodingStyle' XAttribute (by using ns + "encodingStyle"):

    XAttribute encoding = new XAttribute(ns + "encodingStyle", "http://www.w3.org/2001/12/soap-encoding");
    

    The two-parameter XAttribute constructor takes an XName as the first argument. This can either be constructed implicitly from a string (as in the code in your question), or directly by "adding" a string to an XNamespace to create an XName (as above).

提交回复
热议问题