Subscribe to Subscribers
Talk to Webmaster Tony John

Online Members

prasad
baskar
More...


Resources » Code Snippets » General

How to create XML file with dynamic data using C#?


Posted Date:     Category: General    
Author: Member Level: Gold    Points: 15


There is a sample code to create XML file with dynamic data. Code has been developed in C# whereas application is windows based. Scenario is used for businessrule but you can use this for any other approaches also.



 


How to create XML file with dynamic data using C#?
Description
Suppose user wants to create a XML file which has predecided format but user can set attributes at runtime then this code snippet is used.
In this, user can create businessrule alongwith the description and user will give input values for setting those attributes.
XML file will be created as per the dynamic data.
config file is used to set the filepath where we want to store the newly created xml file.
You can create business rules or conditional cases by using this code.

XmlDocument my_XML_doc = new XmlDocument();
// Create root node.
XmlElement XElemRoot = my_XML_doc.CreateElement("BusinessRule");
XElemRoot.SetAttribute("BusinessRuleName", txtBusinessRule.Text);
//Add the node to the document.
my_XML_doc.AppendChild(XElemRoot);
XmlElement Xsource = my_XML_doc.CreateElement("BusinessRuleDescription");
XElemRoot.SetAttribute("BusinessRuleDescription", txtBusinessRuledescription.Text);

if (!Directory.Exists(ConfigurationSettings.AppSettings["user_file_path"] + txtBusinessRule.Text))
{
System.IO.Directory.CreateDirectory(ConfigurationSettings.AppSettings["user_file_path"] + txtBusinessRule.Text);
my_XML_doc.Save(ConfigurationSettings.AppSettings["user_file_path"] + txtBusinessRule.Text + "\\" + txtBusinessRule.Text + ".xml");
MessageBox.Show("BusinessRule Created", "BusinessRule Creation");
}
else
{
MessageBox.Show("Duplicate BusinessRule!", "BusinessRule creation error");
txtBusinessRule.Text = "";
txtBusinessRuledescription.Text = "";
txtBusinessRule.Focus();
}





Did you like this resource? Share it with your friends and show your love!


Responses to "How to create XML file with dynamic data using C#?"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: How to check whether user defined date format matches with element value’s date format at XPath?
    Previous Resource: How to add items of array to combobox using c#?
    Return to Resources
    Post New Resource
    Category: General


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    (No tags found.)



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.