PC Review


Reply
Thread Tools Rate Thread

How to add XML Declaration

 
 
=?Utf-8?B?U2FtdWVsU3VkaGFrYXJK?=
Guest
Posts: n/a
 
      28th Jul 2004
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....

--
ThankZZZ,
SamuelSudhakarJ
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9obiBQYXVsLiBB?=
Guest
Posts: n/a
 
      28th Jul 2004
Dear SamuelSudhakarJ,
Add this to your code..
textWriter.WriteStartDocument(True)

It will create
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
on the top of your XML document.

for further reference, visit this link.
ms-help://MS.NETFrameworkSDK/cpref/html/frlrfSystemXmlXmlTextWriterClassWriteStartDocumentTopic.htm

--
Thanks & Regards,
John Paul. A
MCP


"SamuelSudhakarJ" wrote:

> 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....
>
> --
> ThankZZZ,
> SamuelSudhakarJ

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if declaration =?Utf-8?B?YXNodzE5ODQ=?= Microsoft Excel Programming 2 30th Jan 2006 07:35 PM
Declaration name Robert Hargreaves Microsoft Excel Programming 4 6th Jun 2005 04:48 PM
event-declaration vs interface-event-declaration Alex Sedow Microsoft C# .NET 1 26th Dec 2004 11:03 PM
which declaration to use Peer Microsoft Excel Programming 3 2nd Aug 2004 03:17 PM
Declaration? TJF Microsoft Excel Programming 5 18th Dec 2003 03:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:46 AM.