XmlTextReader.Depth Property gets the depth of the current node in the XML document. : XmlTextReader « XML « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net » XML » XmlTextReaderScreenshots 
XmlTextReader.Depth Property gets the depth of the current node in the XML document.
 

Imports System
Imports System.IO
Imports System.Xml
Imports Microsoft.VisualBasic

public class Sample

  public shared sub Main()

    Dim xmlFrag as string = "<book><misc><style>paperback</style><pages>240</pages></misc></book>"

    Dim nt as NameTable = new NameTable()
    Dim nsmgr as XmlNamespaceManager = new XmlNamespaceManager(nt)

    Dim context as XmlParserContext = new XmlParserContext(nothing, nsmgr, nothing, XmlSpace.None)

    Dim reader as XmlTextReader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context)

    while (reader.Read())
       select case reader.NodeType
         case XmlNodeType.Element:
           Console.Write("{0} {1},{2}  ", reader.Depth, reader.LineNumber, reader.LinePosition)
           Console.WriteLine("<{0}>", reader.Name)
         case XmlNodeType.Text:
           Console.Write("{0} {1},{2}  ", reader.Depth, reader.LineNumber, reader.LinePosition)
           Console.WriteLine("  {0}", reader.Value)
         case XmlNodeType.EndElement:
           Console.Write("{0} {1},{2}  ", reader.Depth, reader.LineNumber, reader.LinePosition)
           Console.WriteLine("</{0}>", reader.Name)
       end select       
    End while           
    reader.Close()      
  End sub
End class

   
  
Related examples in the same category
1.Create XmlTextReader class with the specified file.
2.Create XmlTextReader class with the specified TextReader.
3.XmlTextReader.AttributeCount gets the number of attributes on the current node.
4.XmlTextReader.BaseURI Property gets the base URI of the current node.
5.XmlTextReader.GetAttribute gets the value of the attribute with the specified name.
6.XmlTextReader.GetRemainder gets the remainder of the buffered XML.
7.XmlTextReader.HasValue tells whether the current node can have a Value other than String.Empty.
8.XmlTextReader.IsEmptyElement tells whether the current node is an empty element (for example, ).
9.XmlTextReader.LinePosition Property gets the current line position.
10.XmlTextReader.LocalName Property gets the local name of the current node.
11.XmlTextReader.MoveToFirstAttribute Method moves to the first attribute.
12.XmlTextReader.Name Property gets the qualified name of the current node.
13.XmlTextReader.Normalization Property tells whether to normalize white space and attribute values.
14.XmlTextReader.ReadBase64 Method decodes Base64 and returns the decoded binary bytes.
15.XmlTextReader.XmlLang Property gets the current xml:lang scope.
16.XmlTextReader.XmlSpace Property gets the current xml:space scope.
17.Read binary hex value
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.