.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> XML >> Post New Resource Bookmark and Share   

 Subscribe to Articles

XML Documents : Practical View

Posted By:Gaurav Arora       Posted Date: April 29, 2009    Points: 25    Category: XML    URL: http://www.dotnetspark.com  
 

To generate XML-Schema - it easy with the use of xmlTextReader.
Here, I am try to retrieve xmlSchema with following code-snippet:

1. Create a Design Page


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>





    Reading XML Document


   
   

   
   

   

   
   

   



2. Write Code-Behind for implementation:


/* This Example is a part of different
 * examples shown in Book:
 * C#2005 Beginners: A Step Ahead
 * Written by: Gaurav Arora
 * Reach at :
Gaurav Arora*/

#region Using Namespaces
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Xml.Linq;
#endregion

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    private void ReadXML()
    {
        XmlTextReader xmlReader = new XmlTextReader("http://www.msdotnetheaven.com/?feed=rss2");
//XmlTextReader xmlReader = new XmlTextReader("/myXML.xml");

        xmlReader.Read();

        while (xmlReader.Read())
        {

            // Move to fist element

            xmlReader.MoveToElement();

            txtXML.Text = ("Name:" + xmlReader.Name);

            txtXML.Text += ("Base URI:" + xmlReader.BaseURI);

            txtXML.Text += ("Local Name:" + xmlReader.LocalName);

            txtXML.Text += ("Attribute Count:" + xmlReader.AttributeCount.ToString());

            txtXML.Text += ("Depth:" + xmlReader.Depth.ToString());

            txtXML.Text += ("Line Number:" + xmlReader.LineNumber.ToString());

            txtXML.Text += ("Node Type:" + xmlReader.NodeType.ToString());

            txtXML.Text += ("Attribute Count:" + xmlReader.Value.ToString());
        }
    }

    protected void btnXML_Click(object sender, EventArgs e)
    {
        //Call the readxml
        ReadXML();

        //Set visible to TextBox
        dvXML.Visible = true;

    }
}




Following are the step(s):
1. Start Visual Studio
2. Create a new project
3. Add above two files
4. Press F5
5. Click on ReadXML


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend