DOM load : DOM « XML « VB.Net Tutorial

Home
VB.Net Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statements
5.Date Time
6.Class Module
7.Development
8.Collections
9.Generics
10.Attributes
11.Event
12.LINQ
13.Stream File
14.GUI
15.GUI Applications
16.Windows Presentation Foundation
17.2D Graphics
18.I18N Internationlization
19.Reflection
20.Regular Expressions
21.Security
22.Socket Network
23.Thread
24.Windows
25.XML
26.Database ADO.net
27.Design Patterns
VB.Net
VB.Net by API
VB.Net Tutorial » XML » DOM 
25.4.1.DOM load
public class Test
   public Shared Sub Main
        Dim myDoc As New Xml.XmlDocument
        myDoc.Load("test.xml")

        Dim chpts As Xml.XmlNodeList = myDoc.SelectNodes("/book/chapters/chapter")
        For Each nd As Xml.XmlNode In chpts
            Console.WriteLine(nd.Attributes("id").Value)

        Next


        Dim book As Xml.XmlElement
        book = myDoc.Item("book")
        Console.WriteLine("ISBN: " & book.Attributes("isbn").Value)

        Dim title As Xml.XmlElement
        title = book.Item("title")
        Console.WriteLine(title.InnerText)

        Console.WriteLine("Authors:")
        Dim authors As Xml.XmlElement
        authors = book.Item("authors")

        For Each node As Xml.XmlNode In authors.ChildNodes
            If node.Name = "author" Then
                Console.WriteLine(node.InnerText)
            End If
        Next

        Dim chapters As Xml.XmlElement
        chapters = book.Item("chapters")

        For Each node As Xml.XmlNode In chapters.ChildNodes
            If node.Name = "chapter" Then
                Console.WriteLine(node.Attributes("id").Value)
                Console.WriteLine(node.Attributes("topic").Value)
            End If
        Next
   End Sub
End class
1
2
3
4
5
6
7
8
9
10
K
ISBN: 0-672-32549-7
Start
Authors:
D
A
E
J
1
A
2
B
3
C
4
D
5
E
6
F
7
G
8
H
9
I
10
J
K
L
25.4.DOM
25.4.1.DOM load
25.4.2.DOM save
25.4.3.Reads an XML file and displays each of the nodes.
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.