Creating an XML element with a namespace with XmlDocument.CreateElement()

前端 未结 2 744
孤街浪徒
孤街浪徒 2020-12-04 02:54

I\'m trying to create an XmlDocument using C# and .NET (version 2.0.. yes, version 2.0). I have set the namespace attributes using:

document.Doc         


        
2条回答
  •  一整个雨季
    2020-12-04 03:08

    Maybe you could share what you're expecting as final XML document.

    However from what I understand you want to do that looks like:

        
        
            

    so the code to do that would be:

        XmlDocument document = new XmlDocument();
        document.LoadXml("");
        string soapNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
        XmlAttribute nsAttribute = document.CreateAttribute("xmlns","soapenv","http://www.w3.org/2000/xmlns/");
        nsAttribute.Value = soapNamespace;
        document.DocumentElement.Attributes.Append(namespaceAttribute);
        document.DocumentElement.AppendChild(document.CreateElement("Header",soapNamespace));
    

提交回复
热议问题