0% found this document useful (0 votes)
6 views4 pages

Generate XML Family Document in C#

This document contains C# code that creates an XML document representing a family. It creates XML elements for the family, father, mother, sister, and brother, adding attributes for each person's name and age. It adds the family element to a wrapper element, then saves the XML to a file.

Uploaded by

nishantgupta_ji
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Generate XML Family Document in C#

This document contains C# code that creates an XML document representing a family. It creates XML elements for the family, father, mother, sister, and brother, adding attributes for each person's name and age. It adds the family element to a wrapper element, then saves the XML to a file.

Uploaded by

nishantgupta_ji
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

using System;

using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];

public partial class _Default : [Link]


{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
//Create a new xmlDataDocument

XmlDataDocument myDoc = new XmlDataDocument();

//The familie

XmlElement Familie = [Link]("Familie");

//The elements wrapper

XmlElement wrapper = [Link]("xml");

//Create attributes

XmlAttribute version = [Link]("version");

XmlAttribute encoding = [Link]("encoding");

//Add values to attributes

[Link] = "1.0";

[Link] = "utf-8";

//Append attributes to their correspondent element

[Link](version);

[Link](encoding);

//The Father

XmlElement Father = [Link]("Father");

//Create attributes

XmlAttribute FatherName = [Link]("Name");


XmlAttribute FatherAge = [Link]("Age");

//Add values to attributes

[Link] = "My father";

[Link] = "65";

//Append attributes to their correspondent element

[Link](FatherName);

[Link](FatherAge);

//Add the element to the Familie node

[Link](Father);

//The mother

XmlElement Mother = [Link]("Mother");

//Create attributes

XmlAttribute MotherName = [Link]("Name");

XmlAttribute MotherAge = [Link]("Age");

//Add values to attributes

[Link] = "My mother";

[Link] = "60";

//Append attributes to their correspondent element

[Link](MotherName);

[Link](MotherAge);

//Add the element to the Familie node

[Link](Mother);

//The sister

XmlElement Sister = [Link]("Sister");

//Create attributes

XmlAttribute SisterName = [Link]("Name");

XmlAttribute SisterAge = [Link]("Age");

//Add values to attributes

[Link] = "My sister";


[Link] = "20";

//Append attributes to their correspondent element

[Link](SisterName);

[Link](SisterAge);

//Add the element to the Familie node

[Link](Sister);

//The brother

XmlElement Brother = [Link]("Brother");

//Create attributes

XmlAttribute BrotherName = [Link]("Name");

XmlAttribute BrotherAge = [Link]("Age");

//Add values to attributes

[Link] = "My brother";

[Link] = "21";

//Append attributes to their correspondent element

[Link](BrotherName);

[Link](BrotherAge);

//Add the element to the Familie node

[Link](Brother);

//wrapp all elements nodes in wrapper node

[Link](Familie);

//Add the entire node in to the docuement

[Link](wrapper);

//Save the xml document

[Link](@"C:\[Link]");

//Give a signal that all gonna be all right

[Link]("Document is generated successfully!!");


[Link]();
}
}

You might also like