I need to convert an XML string into an XmlElement

后端 未结 5 812
一个人的身影
一个人的身影 2020-12-14 00:05

I\'m looking for the simplest way to convert a string containing valid XML into an XmlElement object in C#.

How can you turn this into an XmlEleme

5条回答
  •  抹茶落季
    2020-12-14 00:22

    Suppose you already had a XmlDocument with children nodes, And you need add more child element from string.

    XmlDocument xmlDoc = new XmlDocument();
    // Add some child nodes manipulation in earlier
    // ..
    
    // Add more child nodes to existing XmlDocument from xml string
    string strXml = 
      @"wrench
        screwdriver";
    XmlDocumentFragment xmlDocFragment = xmlDoc.CreateDocumentFragment();
    xmlDocFragment.InnerXml = strXml;
    xmlDoc.SelectSingleNode("root").AppendChild(xmlDocFragment);
    

    The Result:

    
      this is earlier manipulation
      wrench
      screwdriver
    
    

提交回复
热议问题