1
Answer

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

Ask a question
tom thomas

tom thomas

15y
4.8k
1
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)
Next Recommended Forum