|
| ||||||||||
| Tags: c sharp, net, programming, xml documents |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Xml with C# in .NET programming
Last edited by Remedy : 03-03-2010 at 06:15 PM. |
|
#2
| ||||
| ||||
| Xml with C# in .NET programming
Same as the HTML, XML collects and exchanges data.The programmer who needed to use the XML file can create a separate XML files to store the data and that may be used as a data source for HTML.Its not only for HTML,the other applications can use it. The file is created and the data is stored in the tags which is same as HTML codding.you can use any editor to create the XML file and save it with the .XML extension. Code: <?xml version ='1.0'?>
<bookstore>
<book>
<title>Fundamentals of Algorithm..</title>
<author>
<firstname>Binny</firstname>
<lastname>Frank</lastname>
</author>
<price>10.99</price>
</book>
......................
............................
.....................
.....................
</bookstore> |
|
#3
| ||||
| ||||
| Reading XML in C# programming Reading XML in C# This section will show you, how to read the XML data from C#.net application.Suppose a simple xml file has been created already named books.xml which is stored in C drive in the documents folder. Code: XmlTextReader txt_Rder = new XmlTextReader("C:\\books.xml"); |
|
#4
| ||||
| ||||
| Writing on XML files from C# Writing on XML files from C#: As the same process of reading the data from xml files,you also can insert new data in the XMl file.One of the XmlWriter class contains the capacity to write the contents to XML documents.It contains some functions and properties which is used to write on to the XML documents. I am going to show you an example for which I will create a file named myXml_data.xml would be stored into C:\\ root directory. The writing statement would be as follows which can be included in the large code: XmlTextWriter textWriter = new XmlTextWriter("C:\\myXmFile.xml", null) ; // the code to create the file in C drive. Now call WriteEndDocument and TextWriter's Close method using the following statement- Code: textWriter.WriteStartDocument(); textWriter.WriteEndDocument(); textWriter.Close(); |
|
#5
| ||||
| ||||
| Creating an XML document with C#
I am going to show you a code demo which can be used to create a simple XMl file and later can be used to store the data.The code to create an XML file would be as follows- Code: using System;
using System.Xml;
namespace PavelTsekov
{
class MainClass
{
XmlDocument xmldcs;
XmlNode xmlnd;
XmlElement xmlelement;
XmlElement xmlelement2;
XmlText xmltxt;
static void Main(string[] args)
{
MainClass aplctn =new MainClass();
}
public MainClass()
{
xmldcs=new XmlDocument();
xmlnd=xmldcs.CreateNode(XmlNodeType.XmlDeclaration,"","");
xmldcs.AppendChild(xmlnd);
xmlelement=xmldcs.CreateElement("","ROOT","");
xmltxt=xmldcs.CreateTextNode("This is the text of the root element");
xmlelement.AppendChild(xmltxt);
xmldcs.AppendChild(xmlelement);
xmlelement2=xmldcs.CreateElement("","SampleElement","");
xmltxt=xmldcs.CreateTextNode("The text of the sample element");
xmlelement2.AppendChild(xmltxt);
xmldcs.ChildNodes.Item(1).AppendChild(xmlelement2);
{
xmldcs.Save("c:\my_data_file.xml");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadLine();
}
}
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Xml with C# in .NET programming" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What does CVS mean in programming? | Gajananvihari | Software Development | 5 | 12-03-2010 04:09 PM |
| What does DOM mean in programming? | Gadin | Software Development | 5 | 11-03-2010 04:33 PM |
| Socket programming: Is any new Programming Language? | Kushan | Software Development | 3 | 14-11-2009 10:13 AM |
| Programming - Mat | garfield1 | Software Development | 7 | 02-02-2009 10:09 PM |
| JetBrains Introduces a New Programming Paradigm With its Meta Programming System | JoeFrat | Software Development | 3 | 13-12-2008 12:49 PM |