Results 1 to 5 of 5

Thread: Xml with C# in .NET programming

  1. #1
    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 07:15 PM.

  2. #2
    Join Date
    Apr 2008
    Posts
    4,642

    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.

  3. #3
    Join Date
    May 2008
    Posts
    4,570

    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.

  4. #4
    Join Date
    May 2008
    Posts
    4,345

    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. #5
    Join Date
    May 2008
    Posts
    4,831

    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();
    }
    }
    }

Similar Threads

  1. What does CVS mean in programming?
    By Gajananvihari in forum Software Development
    Replies: 5
    Last Post: 12-03-2010, 05:09 PM
  2. What does DOM mean in programming?
    By Gadin in forum Software Development
    Replies: 5
    Last Post: 11-03-2010, 05:33 PM
  3. Socket programming: Is any new Programming Language?
    By Kushan in forum Software Development
    Replies: 3
    Last Post: 14-11-2009, 11:13 AM
  4. Programming - Mat
    By garfield1 in forum Software Development
    Replies: 7
    Last Post: 02-02-2009, 11:09 PM
  5. Replies: 3
    Last Post: 13-12-2008, 01:49 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,257,477.63919 seconds with 17 queries