Convert xmlstring into XmlNode

.net, c#, xml

Solution

A very simple way to achieve what you are after is to use the often overlooked XmlDocumentFragment class:

  XmlDocument doc = new XmlDocument();
  XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
  doc.AppendChild(docNode);
  XmlNode rootNode = doc.CreateElement("StatusList");
  doc.AppendChild(rootNode);

  //Create a document fragment and load the xml into it
  XmlDocumentFragment fragment = doc.CreateDocumentFragment();
  fragment.InnerXml = stxml;
  rootNode.AppendChild(fragment);

Problem

i have one xml string like this ``` string stxml="<Status>Success</Status>"; ``` I also creaated one xml document ``` XmlDocument doc = new XmlDocument(); XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null); doc.AppendChild(docNode); XmlNode rootNode = doc.CreateElement("StatusList"); doc.AppendChild(rootNode); ``` i need an output like this. ``` <StatusList> <Status>Success</Status> </StatusList> ``` How can i achieve this.if we using innerhtml,it will insert.But i want to insert xml string as a xmlnode itself

Original source

Related problems