How to create XmlElement attributes with prefix?

前端 未结 4 1384
不知归路
不知归路 2020-12-06 10:46

I need to be able to define an attribute with a prefix in a xml element.

For instance...


         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 11:51

    The XMLDocument.CreateAttribute method can take 3 strings: specified Prefix, LocalName, and NamespaceURI. You could then add the attribute to the element. Something like this might work for you:

    XmlAttribute newAttribute = XmlDocToRef.CreateAttribute("s", "id", "http://niem.gov/niem/structures/2.0");
    TempElement.Attributes.Append(newAttribute):
    

提交回复
热议问题