G
Guest
Dear Pals,
I am creating a XML document through this code:
Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Module Module1
Sub Main()
Dim textWriter As New XmlTextWriter("e:\Emp.xml", _
System.Text.Encoding.UTF8)
textWriter.Formatting = Formatting.Indented
textWriter.WriteDocType("Employees", Nothing, Nothing, Nothing)
textWriter.WriteComment("This file represents a fragment of Employees" & _
"database")
textWriter.WriteStartElement("Employees")
textWriter.WriteStartElement("Employee", Nothing)
textWriter.WriteElementString("FirstName", "John")
textWriter.WriteElementString("LastName", "Doe")
textWriter.WriteElementString("DateOfBirth", "08/09/1968")
textWriter.WriteElementString("DateOfJoining", "04/01/1992")
textWriter.WriteEndElement()
textWriter.WriteEndElement()
' Write the XML to file and close the textWriter
textWriter.Flush()
textWriter.Close()
Console.WriteLine("Press a key to exit.")
Console.ReadLine()
End Sub
End Module
Here is my output:
<!DOCTYPE Employees>
<!--This file represents a fragment of Employeesdatabase-->
<Employees>
<Employee>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<DateOfBirth>08/09/1968</DateOfBirth>
<DateOfJoining>04/01/1992</DateOfJoining>
</Employee>
</Employees>
Can anyone tell me how to add XML Declaration at the top of the document.
Thanks in Advance....
I am creating a XML document through this code:
Imports System
Imports System.IO
Imports System.Xml
Imports System.Text
Module Module1
Sub Main()
Dim textWriter As New XmlTextWriter("e:\Emp.xml", _
System.Text.Encoding.UTF8)
textWriter.Formatting = Formatting.Indented
textWriter.WriteDocType("Employees", Nothing, Nothing, Nothing)
textWriter.WriteComment("This file represents a fragment of Employees" & _
"database")
textWriter.WriteStartElement("Employees")
textWriter.WriteStartElement("Employee", Nothing)
textWriter.WriteElementString("FirstName", "John")
textWriter.WriteElementString("LastName", "Doe")
textWriter.WriteElementString("DateOfBirth", "08/09/1968")
textWriter.WriteElementString("DateOfJoining", "04/01/1992")
textWriter.WriteEndElement()
textWriter.WriteEndElement()
' Write the XML to file and close the textWriter
textWriter.Flush()
textWriter.Close()
Console.WriteLine("Press a key to exit.")
Console.ReadLine()
End Sub
End Module
Here is my output:
<!DOCTYPE Employees>
<!--This file represents a fragment of Employeesdatabase-->
<Employees>
<Employee>
<FirstName>John</FirstName>
<LastName>Doe</LastName>
<DateOfBirth>08/09/1968</DateOfBirth>
<DateOfJoining>04/01/1992</DateOfJoining>
</Employee>
</Employees>
Can anyone tell me how to add XML Declaration at the top of the document.
Thanks in Advance....