Click here to Skip to main content
15,913,254 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem in deployment urgent Pin
Pete O'Hanlon7-Oct-07 10:40
mvePete O'Hanlon7-Oct-07 10:40 
GeneralRe: Problem in deployment urgent Pin
Paul Conrad7-Oct-07 11:05
professionalPaul Conrad7-Oct-07 11:05 
QuestionAccess properties from a class not belonging to the namespace Pin
ESTAN6-Oct-07 9:56
ESTAN6-Oct-07 9:56 
AnswerRe: Access properties from a class not belonging to the namespace Pin
Dave Kreskowiak6-Oct-07 13:35
mveDave Kreskowiak6-Oct-07 13:35 
GeneralRe: Access properties from a class not belonging to the namespace Pin
ESTAN6-Oct-07 13:42
ESTAN6-Oct-07 13:42 
GeneralRe: Access properties from a class not belonging to the namespace Pin
Christian Graus6-Oct-07 13:50
protectorChristian Graus6-Oct-07 13:50 
GeneralRe: Access properties from a class not belonging to the namespace Pin
Dave Kreskowiak6-Oct-07 15:45
mveDave Kreskowiak6-Oct-07 15:45 
Questionreading xml values Pin
jon-806-Oct-07 9:25
professionaljon-806-Oct-07 9:25 
I'm trying to read an xml file that appears to be valid xml, however, the attributes don't seem to be read by an System.Xml.XmlTextReader.

Any idea why?

I couldn't paste the .xml file here because it seems to corrupt the forum, but I can send it; it's a small file.

.NET Framework 2.0
Code
----
using System;

using System.Xml;

namespace ReadingXML2
{

    class Class1
    {

        static void Main(string[] args)
        {

            int ws = 0;

            int pi = 0;

            int dc = 0;

            int cc = 0;

            int ac = 0;

            int et = 0;

            int el = 0;

            int xd = 0;

            // Read a document

            XmlTextReader textReader = new XmlTextReader("sample.xml");

            // Read until end of file

            while (textReader.Read())
            {

                XmlNodeType nType = textReader.NodeType;

                // If node type us a declaration

                if (nType == XmlNodeType.XmlDeclaration)
                {

                    Console.WriteLine("Declaration:" + textReader.Name.ToString());

                    xd = xd + 1;

                }

                // if node type is a comment

                if (nType == XmlNodeType.Comment)
                {

                    Console.WriteLine("Comment:" + textReader.Name.ToString());

                    cc = cc + 1;

                }

                // if node type us an attribute

                if (nType == XmlNodeType.Attribute)
                {

                    Console.WriteLine("Attribute:" + textReader.Name.ToString());

                    ac = ac + 1;

                }

                // if node type is an element

                if (nType == XmlNodeType.Element)
                {

                    Console.WriteLine("Element:" + textReader.Name.ToString());

                    el = el + 1;

                }

                // if node type is an entity\

                if (nType == XmlNodeType.Entity)
                {

                    Console.WriteLine("Entity:" + textReader.Name.ToString());

                    et = et + 1;

                }

                // if node type is a Process Instruction

                if (nType == XmlNodeType.Entity)
                {

                    Console.WriteLine("Entity:" + textReader.Name.ToString());

                    pi = pi + 1;

                }

                // if node type a document

                if (nType == XmlNodeType.DocumentType)
                {

                    Console.WriteLine("Document:" + textReader.Name.ToString());

                    dc = dc + 1;

                }

                // if node type is white space

                if (nType == XmlNodeType.Whitespace)
                {

                    Console.WriteLine("WhiteSpace:" + textReader.Name.ToString());

                    ws = ws + 1;

                }

            }

            // Write the summary

            Console.WriteLine("Total Comments:" + cc.ToString());

            Console.WriteLine("Total Attributes:" + ac.ToString());

            Console.WriteLine("Total Elements:" + el.ToString());

            Console.WriteLine("Total Entity:" + et.ToString());

            Console.WriteLine("Total Process Instructions:" + pi.ToString());

            Console.WriteLine("Total Declaration:" + xd.ToString());

            Console.WriteLine("Total DocumentType:" + dc.ToString());

            Console.WriteLine("Total WhiteSpaces:" + ws.ToString());

        }

    }

}


Program output
--------------
Element:database
WhiteSpace:
Element:table
WhiteSpace:
Element:column
WhiteSpace:
WhiteSpace:
Element:column
WhiteSpace:
WhiteSpace:
Element:column
WhiteSpace:
WhiteSpace:
WhiteSpace:
Element:table
WhiteSpace:
Element:column
WhiteSpace:
WhiteSpace:
Element:column
WhiteSpace:
WhiteSpace:
WhiteSpace:
WhiteSpace:
Total CommentsBlush | :O
Total AttributesBlush | :O
Total Elements:8
Total EntityBlush | :O
Total Process InstructionsBlush | :O
Total DeclarationBlush | :O
Total DocumentTypeBlush | :O
Total WhiteSpaces:16
Press any key to continue . . .

Jon

AnswerRe: reading xml values Pin
pmarfleet6-Oct-07 11:44
pmarfleet6-Oct-07 11:44 
GeneralRe: reading xml values Pin
jon-806-Oct-07 13:09
professionaljon-806-Oct-07 13:09 
GeneralRe: reading xml values Pin
jon-806-Oct-07 21:21
professionaljon-806-Oct-07 21:21 
GeneralRe: reading xml values Pin
pmarfleet6-Oct-07 22:06
pmarfleet6-Oct-07 22:06 
GeneralRe: reading xml values Pin
jon-806-Oct-07 22:20
professionaljon-806-Oct-07 22:20 
QuestionIs there a way to change file location? Pin
C# Beginner Nick6-Oct-07 9:04
C# Beginner Nick6-Oct-07 9:04 
AnswerRe: Is there a way to change file location? Pin
Kristian Sixhøj6-Oct-07 9:18
Kristian Sixhøj6-Oct-07 9:18 
GeneralRe: Is there a way to change file location? [modified] Pin
C# Beginner Nick6-Oct-07 9:20
C# Beginner Nick6-Oct-07 9:20 
GeneralRe: Is there a way to change file location? Pin
Kristian Sixhøj6-Oct-07 9:44
Kristian Sixhøj6-Oct-07 9:44 
GeneralRe: Is there a way to change file location? Pin
C# Beginner Nick6-Oct-07 9:59
C# Beginner Nick6-Oct-07 9:59 
AnswerRe: Is there a way to change file location? Pin
Patrick Etc.7-Oct-07 1:17
Patrick Etc.7-Oct-07 1:17 
QuestionHow do i.... Pin
C# Beginner Nick6-Oct-07 7:21
C# Beginner Nick6-Oct-07 7:21 
AnswerRe: How do i.... Pin
Justin Perez6-Oct-07 7:25
Justin Perez6-Oct-07 7:25 
GeneralRe: How do i.... Pin
C# Beginner Nick6-Oct-07 7:28
C# Beginner Nick6-Oct-07 7:28 
GeneralRe: How do i.... Pin
Justin Perez6-Oct-07 7:45
Justin Perez6-Oct-07 7:45 
GeneralRe: How do i.... Pin
C# Beginner Nick6-Oct-07 7:48
C# Beginner Nick6-Oct-07 7:48 
GeneralRe: How do i.... Pin
Justin Perez6-Oct-07 7:51
Justin Perez6-Oct-07 7:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.