XmlNode newChild = ...; // create a new child element XmlNode parent = ...; // select a parent element parent.PrependChild(newChild); // add the new child element to the beginning of the list of children of the parent element
XmlDocument doc = new XmlDocument(); XmlNode root = doc.CreateElement("root"); doc.AppendChild(root); XmlNode child1 = doc.CreateElement("child1"); root.AppendChild(child1); XmlNode child2 = doc.CreateElement("child2"); root.PrependChild(child2);
XmlDocument doc = new XmlDocument(); doc.LoadXml("In this example, we load an existing XML document into the XmlDocument object and select its root element. We then create a new child element and add it to the beginning of the list of children of the root element using the PrependChild method."); XmlNode root = doc.DocumentElement; XmlNode child3 = doc.CreateElement("child3"); root.PrependChild(child3);