❔ Creating a XML-document and adding subnodes

Can anyone show me how to use XmlDocument or XDocument to create a new Xml-document that has a "<root>" -node. Then in the loop writer.toString() is a new xmldocument in sting-format that I want to add to the root-node.
public static XmlDocument CreateOrderXML(string materialId)
{
Dictionary<string, object> dict = GetData(materialId).Result;

XmlDocument xmlDoc = new XmlDocument();
XDocument xdoc = XDocument.Parse(@"<Root/>");

foreach (var entry in dict)
{

using (var writer = new StringWriter())
{

new XmlSerializer(Type.GetType(entry.Key)).Serialize(writer, entry.Value);

//XmlDocumentFragment fragment = xmlDoc.CreateDocumentFragment();
//fragment.InnerXml = writer.ToString();

}

}

return xmlDoc;
}
public static XmlDocument CreateOrderXML(string materialId)
{
Dictionary<string, object> dict = GetData(materialId).Result;

XmlDocument xmlDoc = new XmlDocument();
XDocument xdoc = XDocument.Parse(@"<Root/>");

foreach (var entry in dict)
{

using (var writer = new StringWriter())
{

new XmlSerializer(Type.GetType(entry.Key)).Serialize(writer, entry.Value);

//XmlDocumentFragment fragment = xmlDoc.CreateDocumentFragment();
//fragment.InnerXml = writer.ToString();

}

}

return xmlDoc;
}
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server