Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Creating an XML Document with the XMLTextWriter Class
[ All Languages » VB.net »  XML]

Total Hit ( 2881)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


To quickly create a new XML document you can use the XMLTextWriter class. There are many ways to create XML in the .NET Framework, but the XMLTextWriter is one of the quickest.

Click here to copy the following block
Dim mywriter As System.Xml.XmlTextWriter

mywriter = New System.Xml.XmlTextWriter("c:\myxml.xml", Nothing)

With mywriter
   .Indentation = 4
  .IndentChar = " "
  .Formatting = .Indentation

  .WriteStartDocument()
  .WriteComment("This Is A List of My Books")

  .WriteStartElement("MyBooks")
  .WriteStartElement("Book")
  .WriteAttributeString("ISBN", "1861005652")
  .WriteAttributeString("Title", "Professional Visual Basic Interoperability")
  .WriteElementString("Author", "Billy Hollis")
  .WriteElementString("Author", "Rockford Lhotka")
  .WriteEndElement() 'For Book
  .WriteEndElement() 'For MyBooks

  .WriteEndDocument()
End With

mywriter.Flush()
mywriter.Close()

Sample Output

Click here to copy the following block
<?xml version="1.0" ?>
<!-- This Is A List of My Books -->
<MyBooks>
    <Book ISBN="1861005652" Title="Professional Visual Basic Interoperability">
        <Author>Billy Hollis</Author>
        <Author>Rockford Lhotka</Author>
    </Book>
</MyBooks>


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.