jsuanque
asked on
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.SqlConnecti on(Configu rationMana ger.Connec tionString s("CENTRIS _SMIConnec tionString ").Connect ionString)
Dim cmd As New Data.SqlClient.SqlCommand( "SMI_P001_ XML_Downlo ad", conn)
cmd.CommandType = Data.CommandType.StoredPro cedure
conn.Open()
'Add parameters (NationalUPN) selected from form for WHERE clause
cmd.Parameters.Add("@Natio nalUPN", Data.SqlDbType.VarChar)
cmd.Parameters("@NationalU PN").Value = DropDownList2.SelectedValu e.ToString
'Add parameters (AcademicYear) selected from form for WHERE clause
cmd.Parameters.Add("@Acade micYear", Data.SqlDbType.Int)
cmd.Parameters("@AcademicY ear").Valu e = DropDownList3.SelectedValu e.ToString
'Add parameters (SchoolDestination) selected from form for WHERE clause
cmd.Parameters.Add("@Schoo lDest", Data.SqlDbType.Int)
cmd.Parameters("@SchoolDes t").Value = DropDownList1.SelectedValu e.ToString
Dim da As New Data.SqlClient.SqlDataAdap ter(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.N TSCHOOLS\D esktop\MyS MIStudentT rackerExpo rt_" & nowString & ".xml"
ds.WriteXml(fileName)
Dim doc As System.Xml.XmlDataDocument = New System.Xml.XmlDataDocument (ds)
Dim transform As New System.Xml.Xsl.XslCompiled Transform( )
transform.Load("D:\Inetpub \wwwroot\W ebSite2\SM I_Tracker_ Download2. xsl")
'transform.Load(Server.Map Path("SMI_ Tracker_Do wnload1.xs l"))
Dim writer As System.Xml.XmlTextWriter = New System.Xml.XmlTextWriter(f ileName, System.Text.Encoding.UTF8)
writer.Formatting = System.Xml.Formatting.Inde nted
writer.Indentation = 2
transform.Transform(doc, Nothing, writer)
End Using
End Sub
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.SqlConnecti
Dim cmd As New Data.SqlClient.SqlCommand(
cmd.CommandType = Data.CommandType.StoredPro
conn.Open()
'Add parameters (NationalUPN) selected from form for WHERE clause
cmd.Parameters.Add("@Natio
cmd.Parameters("@NationalU
'Add parameters (AcademicYear) selected from form for WHERE clause
cmd.Parameters.Add("@Acade
cmd.Parameters("@AcademicY
'Add parameters (SchoolDestination) selected from form for WHERE clause
cmd.Parameters.Add("@Schoo
cmd.Parameters("@SchoolDes
Dim da As New Data.SqlClient.SqlDataAdap
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.N
ds.WriteXml(fileName)
Dim doc As System.Xml.XmlDataDocument
Dim transform As New System.Xml.Xsl.XslCompiled
transform.Load("D:\Inetpub
'transform.Load(Server.Map
Dim writer As System.Xml.XmlTextWriter = New System.Xml.XmlTextWriter(f
writer.Formatting = System.Xml.Formatting.Inde
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>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Found it. I just added ...
writer.WriteStartDocument( )
in the code and Voila.
writer.WriteStartDocument(
in the code and Voila.
ASKER
Thanks though it didn't fix my problem immediately but it certainly did guide me where to look for the issue.
ASKER
Tried your suggestion but that doesn't work.