tom thomas

tom thomas

  • NA
  • 4
  • 0

reading xml schema from c# and retriving all data from it

Sep 10 2009 4:58 AM
dear sir/madam,
i have an xml schema file consisting of data in the following manner

<xs:element name="indicatorSection" type="IndicatorSection"/>
....................
.......
<xs:element name="GRIB">
...............
..................
<xs:documentation>Octet 7</xs:documentation>
<xs:enumeration value="meteorological roduct"/>

[U][B]i would like to get the data from

xs:element name
xs:documentation
xs:enumeration value[/B][/U]

i had the following code :
using System;
using System.Xml;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ReadXMLfromFile
{
    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    class Class1
    {
        static void Main(string[] args)
        {
            TextWriter tws = new StreamWriter("0.txt");


            XmlTextReader reader = new XmlTextReader ("gribv-2schema.xsd");
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element: // The node is an element.
                        Console.Write("<" + reader.Name);
                        Console.WriteLine(">");
                        string documentation = "xs:documentation";
                        if (reader.Name == documentation) { Console.WriteLine("Element"); }
                        tws.WriteLine("<" + reader.Name + ">");
                        
                        Console.ReadLine();
                        
                        
                        
                        break;
                    case XmlNodeType.Text: //Display the text in each element.
                        Console.WriteLine (reader.Value);
                        tws.WriteLine(reader.Value);
                        break;
                    case XmlNodeType.EndElement: //Display the end of the element.
                        Console.Write("</" + reader.Name);
                        Console.WriteLine(">");
                        tws.WriteLine("<" + reader.Name + ">");
                        break;
                }
            }
            Console.ReadLine();
        }
    }
}
    
but it does not seem to read out all the data ,could any one of you please render me help

thanks in advance !

tom

Answers (1)