DOM save : DOM « XML « VB.Net Tutorial

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. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial » XML » DOM 
23. 3. 2. DOM save
 
 

public class DOMSave
   public Shared Sub Main
        Dim myDoc As New Xml.XmlDocument

        myDoc.AppendChild(myDoc.CreateXmlDeclaration("1.0""UTF-8", String.Empty))
        myDoc.AppendChild(myDoc.CreateComment("information about this book"))

        Dim rootBook As Xml.XmlNode =myDoc.AppendChild(myDoc.CreateElement("book"))
        rootBook.Attributes.Append(myDoc.CreateAttribute("isbn"))
        rootBook.Attributes("isbn").Value = "0-672-32549-7"

        Dim title As Xml.XmlNode
        title = rootBook.AppendChild(myDoc.CreateElement("title"))
        title.InnerText = "Start"
        Dim authors As Xml.XmlNode = rootBook.AppendChild(myDoc.CreateElement("authors"))
        Dim Duncan, Andy, Erik, Joel As Xml.XmlNode

        Duncan = authors.AppendChild(myDoc.CreateElement("author"))
        Andy = authors.AppendChild(myDoc.CreateElement("author"))
        Erik = authors.AppendChild(myDoc.CreateElement("author"))
        Joel = authors.AppendChild(myDoc.CreateElement("author"))

        Duncan.InnerText = "D"
        Andy.InnerText = "A"
        Erik.InnerText = "E"
        Joel.InnerText = "J"

        Dim chapters As Xml.XmlNode = myDoc.CreateElement("chapters")

        rootBook.AppendChild(chapters)

        Dim chapterElements(10As Xml.XmlElement

        For i As Integer = To 10
            chapterElements(i= myDoc.CreateElement("chapter")
            With chapterElements(i)
                .Attributes.Append(myDoc.CreateAttribute("id"))
                .Attributes("id").Value =CStr(i + 1)
                .Attributes.Append(myDoc.CreateAttribute("topic"))
            End With
            chapters.AppendChild(chapterElements(i))
        Next


        chapterElements(0).Attributes("topic").Value = "A"
        chapterElements(1).Attributes("topic").Value = "B"
        chapterElements(2).Attributes("topic").Value = "C"
        chapterElements(3).Attributes("topic").Value = "D"
        chapterElements(4).Attributes("topic").Value = "E"
        chapterElements(5).Attributes("topic").Value = "F"
        chapterElements(6).Attributes("topic").Value = "G"
        chapterElements(7).Attributes("topic").Value = "H"
        chapterElements(8).Attributes("topic").Value = "I"
        chapterElements(9).Attributes("topic").Value = "J"
        chapterElements(10).Attributes("id").Value = "K"
        chapterElements(10).Attributes("topic").Value = "L"

        Dim myWriter As New Xml.XmlTextWriter("test.xml", System.Text.Encoding.UTF8)

        myWriter.Formatting = Xml.Formatting.Indented
        myDoc.Save(myWriter)
        myWriter.Close()
   End Sub
End class

        
  
23. 3. DOM
23. 3. 1. DOM load
23. 3. 2. DOM save
w_w__w_.___j___a___v__a2s__.c__o__m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.