Write XML Dynamically according to tree structure in windows c#
-
Hi All, I have an "Acount" and my Acount has multiple "users" . And my user have three settings like App,Web,Key So we have to write XML on this behalf of tree. Structure like - Acount User1 Acount Setting web App Key User2 Acount Setting web App Key I have create XML like same as structure.
-
Hi All, I have an "Acount" and my Acount has multiple "users" . And my user have three settings like App,Web,Key So we have to write XML on this behalf of tree. Structure like - Acount User1 Acount Setting web App Key User2 Acount Setting web App Key I have create XML like same as structure.
Have a look at the
XmlDocument
class here[^]. Basically you'd create aXmlDocument
object and addXmlElement
[^] instances. For example:XmlDocument document = new XmlDocument();
// Create the root Account element.
XmlElement root = document.CreateElement("Account");
// Add attributes to the element
root.SetAttribute("SomeAttribute", "42");
// Add the element to the document's tree.
document.AppendChild(root);// Create the child elements
XmlElement child = document.CreateElement("User1");
// Add the child to the root element
root.AppendChild(child);// Create a grandchild
XmlELement grandchild = document.CreateElement("AccountSetting");
child.AppendChild(grandchild);//etc, etc...
//Finally you could save the document to file:
document.Save(pathToMyXmlFile);2A
-
Hi All, I have an "Acount" and my Acount has multiple "users" . And my user have three settings like App,Web,Key So we have to write XML on this behalf of tree. Structure like - Acount User1 Acount Setting web App Key User2 Acount Setting web App Key I have create XML like same as structure.
Markovl's suggestion is good and I use it for small amounts of data. For large amounts of data I tend to use an XmlWriter -- I keep thinking of writing something about it.