Missing Tag <?xml version="1.0" encoding="ISO-8859-1" ?> in my XML output file

Hi,
On my web page, a button generates an XML file (on click) whose data comes from SQL server. This XML file output is to be used as an import file to a legacy system. XML file is generated without dramas but the problem is that the tag <?xml version="1.0" encoding="ISO-8859-1" ?> is not included on the top of the XMl file, this tag is needed by the recievning application.

I'm practically out of clue as to where or what i missed. Can anyone help me understand and suggest a fix on my problem?

Here is the event on my webpage. And on the snippet is my XSL template...


    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Using conn As New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("CENTRIS_SMIConnectionString").ConnectionString)
            Dim cmd As New Data.SqlClient.SqlCommand("SMI_P001_XML_Download", conn)
            cmd.CommandType = Data.CommandType.StoredProcedure
            conn.Open()
            'Add parameters (NationalUPN) selected from form for WHERE clause
            cmd.Parameters.Add("@NationalUPN", Data.SqlDbType.VarChar)
            cmd.Parameters("@NationalUPN").Value = DropDownList2.SelectedValue.ToString

            'Add parameters (AcademicYear) selected from form for WHERE clause
            cmd.Parameters.Add("@AcademicYear", Data.SqlDbType.Int)
            cmd.Parameters("@AcademicYear").Value = DropDownList3.SelectedValue.ToString

            'Add parameters (SchoolDestination) selected from form for WHERE clause
            cmd.Parameters.Add("@SchoolDest", Data.SqlDbType.Int)
            cmd.Parameters("@SchoolDest").Value = DropDownList1.SelectedValue.ToString

            Dim da As New Data.SqlClient.SqlDataAdapter(cmd)
            Dim ds As New Data.DataSet
            da.Fill(ds)
            Dim nowString As String = Now.ToString("dd-MM-yyyy hh.mm.ss")
            Dim fileName As String = "D:\TEMP\000LLL_CTF_SMI_" & nowString & ".xml"
            'Dim fileName As String = "C:\Documents and Settings\jackson.suanque.NTSCHOOLS\Desktop\MySMIStudentTrackerExport_" & nowString & ".xml"
            ds.WriteXml(fileName)
            Dim doc As System.Xml.XmlDataDocument = New System.Xml.XmlDataDocument(ds)
            Dim transform As New System.Xml.Xsl.XslCompiledTransform()
            transform.Load("D:\Inetpub\wwwroot\WebSite2\SMI_Tracker_Download2.xsl")
            'transform.Load(Server.MapPath("SMI_Tracker_Download1.xsl"))
            Dim writer As System.Xml.XmlTextWriter = New System.Xml.XmlTextWriter(fileName, System.Text.Encoding.UTF8)
            writer.Formatting = System.Xml.Formatting.Indented
            writer.Indentation = 2
            transform.Transform(doc, Nothing, writer)
        End Using
    End Sub


<?xml version="1.0" standalone="yes" ?> 
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="yes" encoding="ISO-8859-1" omit-xml-declaration="no" /> 
- <xsl:template match="/">
- <CTfile>
  <xsl:call-template name="callHeader" /> 
  <xsl:call-template name="callCTFpupilData" /> 
  </CTfile>
  </xsl:template>
- <xsl:template name="callHeader">
- <Header>
- <DocumentName>
  <xsl:value-of select="/NewDataSet/Table/DocumentName" /> 
  </DocumentName>
- <CTFversion>
  <xsl:value-of select="/NewDataSet/Table/CTFversion" /> 
  </CTFversion>
- <DateTime>
  <xsl:value-of select="/NewDataSet/Table/DateTime" /> 
  </DateTime>
- <DocumentQualifier>
  <xsl:value-of select="/NewDataSet/Table/DocumentQualifier" /> 
  </DocumentQualifier>
- <SupplierID>
  <xsl:value-of select="/NewDataSet/Table/SupplierID" /> 
  </SupplierID>
  <xsl:call-template name="callSourceSchool" /> 
  <xsl:call-template name="callDestSchool" /> 
  </Header>
  </xsl:template>
- <xsl:template name="callSourceSchool">
- <SourceSchool>
- <LEA>
  <xsl:value-of select="/NewDataSet/Table/SchoolSourceLEACode" /> 
  </LEA>
- <Estab>
  <xsl:value-of select="/NewDataSet/Table/SourceSchoolEstablishmentCode" /> 
  </Estab>
- <SchoolName>
  <xsl:value-of select="/NewDataSet/Table/SchoolName" /> 
  </SchoolName>
- <AcademicYear>
  <xsl:value-of select="/NewDataSet/Table/AcademicYear" /> 
  </AcademicYear>
  </SourceSchool>
  </xsl:template>
- <xsl:template name="callDestSchool">
- <DestSchool>
- <LEA>
  <xsl:value-of select="/NewDataSet/Table/DestLEA" /> 
  </LEA>
- <Estab>
  <xsl:value-of select="/NewDataSet/Table/DestEstab" /> 
  </Estab>
  </DestSchool>
  </xsl:template>
- <xsl:template name="callCTFpupilData">
- <CTFpupilData>
  <xsl:call-template name="callPupil" /> 
  </CTFpupilData>
  </xsl:template>
- <xsl:template name="callPupil">
- <Pupil>
- <UPN>
  <xsl:value-of select="/NewDataSet/Table/NationalUPN" /> 
  </UPN>
- <Surname>
  <xsl:value-of select="/NewDataSet/Table/LegalSurname" /> 
  </Surname>
- <ForeName>
  <xsl:value-of select="/NewDataSet/Table/Firstname" /> 
  </ForeName>
- <DOB>
  <xsl:value-of select="/NewDataSet/Table/DOB" /> 
  </DOB>
- <Gender>
  <xsl:value-of select="/NewDataSet/Table/Sex" /> 
  </Gender>
  <xsl:call-template name="callBasicDetails" /> 
  <xsl:call-template name="callAddress" /> 
  </Pupil>
  </xsl:template>
- <xsl:template name="callBasicDetails">
- <BasicDetails>
- <FormerUPN>
  <xsl:value-of select="/NewDataSet/Table/PreviousNationalUPN" /> 
  </FormerUPN>
- <PreferredSurname>
  <xsl:value-of select="/NewDataSet/Table/Surname" /> 
  </PreferredSurname>
- <PreferredForename>
  <xsl:value-of select="/NewDataSet/Table/OtherNames" /> 
  </PreferredForename>
- <NCYearActual>
  <xsl:value-of select="/NewDataSet/Table/NCYearActual" /> 
  </NCYearActual>
- <Ethnicity>
  <xsl:value-of select="/NewDataSet/Table/Ethnicity" /> 
  </Ethnicity>
- <EthnicitySource>
  <xsl:value-of select="/NewDataSet/Table/EthnicitySource" /> 
  </EthnicitySource>
  <xsl:call-template name="callLanguages" /> 
- <FSMEligible>
  <xsl:value-of select="/NewDataSet/Table/FSMeligible" /> 
  </FSMEligible>
- <MedicalFlag>
  <xsl:value-of select="/NewDataSet/Table/MedicalFlagQualifier" /> 
  </MedicalFlag>
- <EnrolStatus>
  <xsl:value-of select="/NewDataSet/Table/EnrolStatus" /> 
  </EnrolStatus>
- <Statemented>
  <xsl:value-of select="/NewDataSet/Table/SENStatemented" /> 
  </Statemented>
  </BasicDetails>
  </xsl:template>
- <xsl:template name="callLanguages">
- <Languages>
- <Type>
- <LanguageQualifier>
  <xsl:value-of select="/NewDataSet/Table/LanguageQualifier" /> 
  </LanguageQualifier>
- <Language>
  <xsl:value-of select="/NewDataSet/Table/Language" /> 
  </Language>
  </Type>
  </Languages>
  </xsl:template>
- <xsl:template name="callAddress">
- <Address>
- <AddressLines>
- <Line1>
  <xsl:value-of select="/NewDataSet/Table/AddressLine1" /> 
  </Line1>
- <Line2>
  <xsl:value-of select="/NewDataSet/Table/AddressLine2" /> 
  </Line2>
- <Line3>
  <xsl:value-of select="/NewDataSet/Table/AddressLine3" /> 
  </Line3>
- <Line4>
  <xsl:value-of select="/NewDataSet/Table/Town" /> 
  </Line4>
- <Line5>
  <xsl:value-of select="/NewDataSet/Table/County" /> 
  </Line5>
- <Postcode>
  <xsl:value-of select="/NewDataSet/Table/PostCode" /> 
  </Postcode>
  </AddressLines>
  </Address>
  </xsl:template>
  </xsl:stylesheet>

Open in new window

jsuanqueAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DelTremeCommented:
In this line:

Dim writer As System.Xml.XmlTextWriter = New System.Xml.XmlTextWriter(fileName, System.Text.Encoding.UTF8)

You create a TextWriter using the UTF8 encoding. Try this one instead:

Dim writer As System.Xml.XmlTextWriter = New System.Xml.XmlTextWriter(fileName, System.Text.Encoding.GetEncoding(1252))

That should at least output the data in Latin-1 (ISO-8859-1).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jsuanqueAuthor Commented:
Hello DelTreme,

Tried your suggestion but that doesn't work.
0
jsuanqueAuthor Commented:
Found it. I just added ...
            writer.WriteStartDocument()
in the code and Voila.
0
jsuanqueAuthor Commented:
Thanks though it didn't fix my problem immediately but it certainly did guide me where to look for the issue.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.