xml header encoding declaration

Asked By bobby naderi
03-Nov-09 04:53 PM
Earn up to 0 extra points for answering this tough question.
building an xml generator in vb within excel, how can i get the encoding declaration to appear as the first line?

<?xml version="1.0" encoding="ISO-8859-1" ?>

  re

Web Star replied to bobby naderi
03-Nov-09 10:26 PM

u can use WriteStartDocument for that encoding

also see this

http://support.microsoft.com/kb/317169

  I guess the answer above points to VB.Net and not VB 6.0.

[)ia6l0 iii replied to bobby naderi
04-Nov-09 01:33 PM
In VB 6.0, you would write the XML Declaration like this:

Dim memory_stream As New MemoryStream
Dim xmlTextWriter As New XmlTextWriter(memory_stream, System.Text.Encoding.UTF8)
' Write the XML declaration.
xmlTextWriter.WriteStartDocument(True)

And if you happen to migrate to VB.Net anytime,  you could use the XMLDocument class's CreateXmlDeclaration method. Sample snippet provided below.

//Create or Load the Xml Document.
XmlDocument xmlDoc = new XmlDocument();
//Create an XML declaration. 
XmlDeclaration xmlDeclartion = xmlDoc.CreateXmlDeclaration("1.0",null,null);
Create New Account