Build an XML Document : XML File Creation « XML « VB.Net

VB.Net
1. 2D
2. Application
3. Class
4. Data Structure
5. Database ADO.net
6. Development
7. Event
8. File Directory
9. Generics
10. GUI
11. Language Basics
12. Network Remote
13. Thread
14. Windows System
15. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VB.Net » XML » XML File CreationScreenshots 
Build an XML Document
Build an XML Document

Imports System
Imports System.Xml
Imports System.IO

Public Class MainClass

   Shared Sub Main()
        Dim memory_stream As New MemoryStream()
        Dim xml_text_writer As New XmlTextWriter(memory_stream, System.Text.Encoding.UTF8)

        xml_text_writer.Formatting = Formatting.Indented
        xml_text_writer.Indentation = 4

        xml_text_writer.WriteStartDocument(True)

        xml_text_writer.WriteStartElement("Employees")

        MakeEmployee(xml_text_writer, "A""A"1)
        MakeEmployee(xml_text_writer, "B""B"2)
        MakeEmployee(xml_text_writer, "C""C"3)

        xml_text_writer.WriteEndElement()

        xml_text_writer.WriteEndDocument()
        xml_text_writer.Flush()

        Dim stream_reader As New StreamReader(memory_stream)

        memory_stream.Seek(0, SeekOrigin.Begin)
        Console.WriteLinestream_reader.ReadToEnd())

        xml_text_writer.Close()
   End Sub 

    ' Add a node to the document.
   Shared Private Sub MakeEmployee(ByVal xml_text_writer As XmlTextWriter, ByVal first_name As String, ByVal last_name As String, ByVal emp_id As Integer)
        ' Start the Employee element.
        xml_text_writer.WriteStartElement("Employee")

        ' Write the FirstName.
        xml_text_writer.WriteStartElement("FirstName")
        xml_text_writer.WriteString(first_name)
        xml_text_writer.WriteEndElement()

        ' Write the LastName.
        xml_text_writer.WriteStartElement("LastName")
        xml_text_writer.WriteString(last_name)
        xml_text_writer.WriteEndElement()

        ' Write the EmployeeId.
        xml_text_writer.WriteStartElement("EmployeeId")
        xml_text_writer.WriteString(emp_id.ToString)
        xml_text_writer.WriteEndElement()

        ' Close the Employee element.
        xml_text_writer.WriteEndElement()
    End Sub

End Class

           
       
Related examples in the same category
1. Use XmlWriter to generate XML documentUse XmlWriter to generate XML document
2. Create XML document: XmlDocument, XmlAttribute, XmlElement
ww___w___.___j_av_a___2__s_.__c_o___m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.