M. Fawad Surosh M. Fawad Surosh - 1 month ago 5
C# Question

Inject a node inside XmlNode

I have a quick question:

using C#, how can I inject a node inside XmlNode please. I don't want to involve XmlDocument in my specific method.



If you do not want to pass a XmlDocument instance in your method parameter list, then you can get the XmlDocument from the XmlNode instance by the OwnerDocument property.

Like in this example:

public void MyMethod(XmlNode node)
      var newElement = node.OwnerDocument.CreateElement("element");

Hope this helps.