Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



Xml with C# in .NET programming

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 03-03-2010
Member
 
Join Date: Dec 2009
Posts: 192
Xml with C# in .NET programming
  

I am a newbie for .Net programming with C# languages.I need to know that how many different types of operations can be possible with the manipulation of C#.NET and XML.Like creating XML document and reading it from the source.If you have some suggestion then please share and guide with me.


Last edited by Remedy : 03-03-2010 at 06:15 PM.
Reply With Quote
  #2  
Old 03-03-2010
Member
 
Join Date: Apr 2008
Posts: 4,641
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>
The .... shows the same procedure would be followed for next record.
Reply With Quote
  #3  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 4,565
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");
You can use this above statement between the codes where you need to read the XML files.
Reply With Quote
  #4  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 4,338
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();
Reply With Quote
  #5  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 4,828
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();
}
}
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 01:20 PM.