Skip to main content

How to Genrate XML file in C#

How to Genrate XML file in C#

Create File


xmldocument doc=new xmldocument();
doc.save(@"c:/program files/file name/add.xml");

ADD Attributes And Save

XmlDocument XD = new XmlDocument();
XmlNode Root = XD.AppendChild(XD.CreateElement("Root"));
XmlNode Child = Root.AppendChild(XD.CreateElement("Child"));
XmlAttribute ChildAtt =Child.Attributes.Append(XD.CreateAttribute("Attribute"));
ChildAtt.InnerText = "My innertext";
Child.InnerText = "Node Innertext";
XD.Save("Add.xml");

Example

using System;
using System.Xml;
 
public class GenerateXml {
private static void Main() {
XmlDocument doc = new XmlDocument();
XmlNode docNode = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
doc.AppendChild(docNode);
 
XmlNode productsNode = doc.CreateElement("products");
doc.AppendChild(productsNode);
 
XmlNode productNode = doc.CreateElement("product");
XmlAttribute productAttribute = doc.CreateAttribute("id");
productAttribute.Value = "01";
productNode.Attributes.Append(productAttribute);
productsNode.AppendChild(productNode);
 
XmlNode nameNode = doc.CreateElement("Name");
nameNode.AppendChild(doc.CreateTextNode("Java"));
productNode.AppendChild(nameNode);
XmlNode priceNode = doc.CreateElement("Price");
priceNode.AppendChild(doc.CreateTextNode("Free"));
productNode.AppendChild(priceNode);
 
// Create and add another product node.
productNode = doc.CreateElement("product");
productAttribute = doc.CreateAttribute("id");
productAttribute.Value = "02";
productNode.Attributes.Append(productAttribute);
productsNode.AppendChild(productNode);
nameNode = doc.CreateElement("Name");
nameNode.AppendChild(doc.CreateTextNode("C#"));
productNode.AppendChild(nameNode);
priceNode = doc.CreateElement("Price");
priceNode.AppendChild(doc.CreateTextNode("Free"));
productNode.AppendChild(priceNode);
 

Thanks For Read.....8-)

Comments

Popular posts from this blog

How to get First,Last,Next,Previews Data in .Net C#

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.Odbc; using System.IO; namespace WindowsApplication1 {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }         OdbcDataAdapter da;         DataSet ds;         int i = 0;         int j;         OdbcConnection conn;         int last;         private void Form1_Load( object sender, EventArgs e)         {             conn = new OdbcConnection ( "dsn=t1" );             conn.Open();             da = new OdbcDataAdapter ( "select * from emp" , conn);             OdbcCommandBuilder builder = new OdbcCommandBuilder (da);             ds = new DataSet ();             da.Fill(ds, "emp" );             dataGridView1.DataSource = ds.Tabl

MIME Types list

Multipurpose Internet Mail Extensions (MIME) is an Internet standard that extends the format of email to support: Text in character sets other than ASCII Non-text attachments: audio, video, images, application programs etc. Message bodies with multiple parts Header information in non-ASCII character sets    MIME Types list   Suffixes Mime .3dm x-world/x-3dmf .3dmf x-world/x-3dmf .a application/octet-stream .aab application/x-authorware-bin .aam application/x-authorware-map .aas application/x-authorware-seg .abc text/vnd.abc .acgi text/html .afl video/animaflex .ai application/postscript .aif audio/aiff .aif audio/x-aiff .aifc audio/aiff .aifc audio/x-aiff .aiff audio/aiff .aiff audio/x-aiff .aim application/x-aim .aip text/x-audiosoft-intra .ani application/x-navi-animation .aos application/x-nokia-9000-communicator-add-on-software .aps application/mime .arc application/octet-str

How to put counter of remaining charector of text in textbox

How to put counter for char remaining in textbox Html <asp:TextBox runat="server" ID="TxtBody" CssClass="form-control" TextMode="MultiLine" Rows="5" placeholder="Body" MaxLength="159" ></asp:TextBox> <div id="Textremaining"></div> Javascript $(document).ready(function() {     var maxChar = 159;     $('#Textremaining').html(maxChar + ' remaining');     $('#<%=TxtBody.ClientID%>').keyup(function() {         var length = $('#<%=TxtBody.ClientID%>').val().length;         var remaining = maxChar - length;         $('#Textremaining').html(remaining  + ' characters remaining');     }); });