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

Posted on 2009-07-16
Last Modified: 2012-05-07
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
            '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
            Dim nowString As String = Now.ToString("dd-MM-yyyy")
            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"
            Dim doc As System.Xml.XmlDataDocument = New System.Xml.XmlDataDocument(ds)
            Dim transform As New System.Xml.Xsl.XslCompiledTransform()
            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="" 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" /> 



- <xsl:template name="callHeader">

- <Header>

- <DocumentName>

  <xsl:value-of select="/NewDataSet/Table/DocumentName" /> 


- <CTFversion>

  <xsl:value-of select="/NewDataSet/Table/CTFversion" /> 


- <DateTime>

  <xsl:value-of select="/NewDataSet/Table/DateTime" /> 


- <DocumentQualifier>

  <xsl:value-of select="/NewDataSet/Table/DocumentQualifier" /> 


- <SupplierID>

  <xsl:value-of select="/NewDataSet/Table/SupplierID" /> 


  <xsl:call-template name="callSourceSchool" /> 

  <xsl:call-template name="callDestSchool" /> 



- <xsl:template name="callSourceSchool">

- <SourceSchool>

- <LEA>

  <xsl:value-of select="/NewDataSet/Table/SchoolSourceLEACode" /> 


- <Estab>

  <xsl:value-of select="/NewDataSet/Table/SourceSchoolEstablishmentCode" /> 


- <SchoolName>

  <xsl:value-of select="/NewDataSet/Table/SchoolName" /> 


- <AcademicYear>

  <xsl:value-of select="/NewDataSet/Table/AcademicYear" /> 




- <xsl:template name="callDestSchool">

- <DestSchool>

- <LEA>

  <xsl:value-of select="/NewDataSet/Table/DestLEA" /> 


- <Estab>

  <xsl:value-of select="/NewDataSet/Table/DestEstab" /> 




- <xsl:template name="callCTFpupilData">

- <CTFpupilData>

  <xsl:call-template name="callPupil" /> 



- <xsl:template name="callPupil">

- <Pupil>

- <UPN>

  <xsl:value-of select="/NewDataSet/Table/NationalUPN" /> 


- <Surname>

  <xsl:value-of select="/NewDataSet/Table/LegalSurname" /> 


- <ForeName>

  <xsl:value-of select="/NewDataSet/Table/Firstname" /> 


- <DOB>

  <xsl:value-of select="/NewDataSet/Table/DOB" /> 


- <Gender>

  <xsl:value-of select="/NewDataSet/Table/Sex" /> 


  <xsl:call-template name="callBasicDetails" /> 

  <xsl:call-template name="callAddress" /> 



- <xsl:template name="callBasicDetails">

- <BasicDetails>

- <FormerUPN>

  <xsl:value-of select="/NewDataSet/Table/PreviousNationalUPN" /> 


- <PreferredSurname>

  <xsl:value-of select="/NewDataSet/Table/Surname" /> 


- <PreferredForename>

  <xsl:value-of select="/NewDataSet/Table/OtherNames" /> 


- <NCYearActual>

  <xsl:value-of select="/NewDataSet/Table/NCYearActual" /> 


- <Ethnicity>

  <xsl:value-of select="/NewDataSet/Table/Ethnicity" /> 


- <EthnicitySource>

  <xsl:value-of select="/NewDataSet/Table/EthnicitySource" /> 


  <xsl:call-template name="callLanguages" /> 

- <FSMEligible>

  <xsl:value-of select="/NewDataSet/Table/FSMeligible" /> 


- <MedicalFlag>

  <xsl:value-of select="/NewDataSet/Table/MedicalFlagQualifier" /> 


- <EnrolStatus>

  <xsl:value-of select="/NewDataSet/Table/EnrolStatus" /> 


- <Statemented>

  <xsl:value-of select="/NewDataSet/Table/SENStatemented" /> 




- <xsl:template name="callLanguages">

- <Languages>

- <Type>

- <LanguageQualifier>

  <xsl:value-of select="/NewDataSet/Table/LanguageQualifier" /> 


- <Language>

  <xsl:value-of select="/NewDataSet/Table/Language" /> 





- <xsl:template name="callAddress">

- <Address>

- <AddressLines>

- <Line1>

  <xsl:value-of select="/NewDataSet/Table/AddressLine1" /> 


- <Line2>

  <xsl:value-of select="/NewDataSet/Table/AddressLine2" /> 


- <Line3>

  <xsl:value-of select="/NewDataSet/Table/AddressLine3" /> 


- <Line4>

  <xsl:value-of select="/NewDataSet/Table/Town" /> 


- <Line5>

  <xsl:value-of select="/NewDataSet/Table/County" /> 


- <Postcode>

  <xsl:value-of select="/NewDataSet/Table/PostCode" /> 






Open in new window

Question by:jsuanque
  • 3

Accepted Solution

DelTreme earned 250 total points
ID: 24869655
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).

Author Comment

ID: 24874405
Hello DelTreme,

Tried your suggestion but that doesn't work.

Author Comment

ID: 24947225
Found it. I just added ...
in the code and Voila.

Author Closing Comment

ID: 31604220
Thanks though it didn't fix my problem immediately but it certainly did guide me where to look for the issue.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Tool Box 2 35
Exit the loop 4 35
Code works but it's slow 24 42
Configure a Bean in an XML file 4 12
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now