Click here to Skip to main content
15,909,742 members
Home / Discussions / C#
   

C#

 
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 
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 
This code should work

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 is an element   
                if (nType == XmlNodeType.Element)  
                {                   
                    Console.WriteLine("Element:" + textReader.Name.ToString());    
                    el = el + 1;
                    if (textReader.HasAttributes)
                    {
                        while (textReader.MoveToNextAttribute())
                        {
                            Console.WriteLine("Attribute:" + textReader.Name.ToString());
                            ac = ac + 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());      
        }


The XmlTextReader has specific methods for iterating through Attributes. Use these when you encounter an Element node.

Paul Marfleet

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 
AnswerRe: How do i.... Pin
Anthony Mushrow6-Oct-07 12:36
professionalAnthony Mushrow6-Oct-07 12:36 
QuestionC# coding standards Pin
GuyThiebaut6-Oct-07 6:59
professionalGuyThiebaut6-Oct-07 6:59 
AnswerRe: C# coding standards Pin
Justin Perez6-Oct-07 7:51
Justin Perez6-Oct-07 7:51 
GeneralRe: C# coding standards Pin
GuyThiebaut6-Oct-07 8:01
professionalGuyThiebaut6-Oct-07 8:01 

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.