tags:

views:

62

answers:

2

how can i merge the following xml string

<employee>
    <name>cliff</name> 
</employee>

to my existing xml document object

    XmlDocument xmlDoc = new XmlDocument();
        XmlElement xmlCompany = xmlDoc.CreateElement("Company");

the final output should look like

<Company>
 <employee>
    <name>cliff</name> 
 </employee>
</Company>

thanks

+2  A: 

You could use the InnerXml property of your company Element:

string xmlString = "<employee><name>cliff</name></employee>";
XmlDocument xmlDoc = new XmlDocument();
XmlElement xmlCompany = xmlDoc.CreateElement("Company");
xmlCompany.InnerXml = xmlString;
Leom Burke
never thought of that thanks!!
CliffC
+1  A: 

Using XLinq APIs

    XElement existing = XElement.Parse(@"<employee> 
                                             <name>cliff</name>  
                                         </employee>");
    XElement newElement = new XElement("company", existing);
Islam Ibrahim