473,513 Members | 3,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to add XML Declaration

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
Jul 21 '05 #1
1 3571
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/frlrfSystemXmlXmlTextWriterClassWriteStartDocument Topic.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

Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

83
6423
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in C. It can cause very ugly errors,like this: epsilon=0 S=0 while epsilon<10: S=S+epsilon
8
2446
by: newmans | last post by:
Perhaps one of the experts can straighten me out on this point... In Bjarne Stroustrup's book 'The C++ Programming Language' 3rd Edition, section 4.9, indicates that typedef complex<short> Point; is not only a declaration, but also a definition. The ISO/IEC 14882:2003(E) standard states in section 3.1 clause 2 that
10
20836
by: Kobu | last post by:
My question is about the use and meaning of the terms "declaration" and "definition" as it pertains to the C language. I've read sources that mix the two up when talking about such things as setting aside storage for an object, defining/declaring a struct, parts of a function, referencing an external variable in another module. ...
25
2775
by: venky | last post by:
Hi main() { int x; /* it declaration or defination??*/ }
4
6092
by: nospam_timur | last post by:
Let's say I have two files, myfile.h and myfile.c: myfile.h: int myfunction(int x); myfile.c: #include "myfile.h"
9
8865
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've *defined* "x"'s value to be 10, isn't above statement a
2
2579
by: Alan | last post by:
Does a template class declaration, like template <class T> have to come immediately prior to the declaration of the function, e.g., T do_something (T something) { . . . } that uses it?
15
14889
by: vaib | last post by:
hi to all.i'd like to know the actual difference between variable declaration and definition.it would be very helpful if anyone out there wud help me out with this thing.i'm writing here after here after a long time since people here also helped me out with my lexer. thanking in anticipation.
6
3152
by: WaterWalk | last post by:
I find friend declaration just very tricky. I tried the following examples on both MingW(gcc 3.4.2) and VC++ 2005. The results are surprising. Example1: namespace ns1 { class Test { friend void func()
10
4315
by: tvnaidu | last post by:
I am using Three pthread functions below, I got ISO error, then I declared int variable called val123, then I assigned, but still I am getting error, any idea?. also I included pthread.h. compiling in Linux with GCC. pthread_cond_signal(&(receiverConf->receive_q_cond)); pthread_cond_destroy(&(receiverConf->receive_q_cond));...
0
7177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7123
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4756
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3248
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
811
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.