473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Can't get a declaration

Background: I have taken an excel spreadsheet with the formatting I
want, saved it as XML, then converted it to an XSL document to use it
as a sort of template. Added some for-each select functionality and am
able to populate it with data from good old Northwind.

Everything is working great except one exasperating problem: the final
XML document does not include an xml declaration (i.e. <?xml
version="1.0"?>). It seems that the following line in my XSL document
should do the trick: <xsl:output method="xml" version="1.0"
encoding="utf-16"/> But sadly it does not.

I thought this was a simple problem but have been googling for two days
now with no luck. Can anyone shed some light?

The C# code and XSL follow (Uses the Northwind database):

private void button1_Click(object sender, System.EventArgs e)
{
string s = "SELECT TOP 10 * FROM [Order Details]";
string OutXML = @"C:\Documents and Settings\gbarker\My
Documents\ExcelXMLTest\Orders.xml";
string XSL = @"C:\Documents and Settings\gbarker\My
Documents\ExcelXMLTest\Orders.xsl";

System.Data.SqlClient.SqlConnection cn = new
System.Data.SqlClient.SqlConnection("Server=WIN2KD EV1;Database=Northwind;USER
ID=SA;Password=password");
System.Data.SqlClient.SqlCommand cmd = new
System.Data.SqlClient.SqlCommand(s, cn);
cn.Open();
System.Data.DataTable dt = new DataTable();
System.Data.DataSet ds = new DataSet();
System.Data.SqlClient.SqlDataAdapter da = new
System.Data.SqlClient.SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(ds);
cn.Close();

ds.WriteXml(OutXML);

System.Xml.XPath.XPathDocument xpd = new
System.Xml.XPath.XPathDocument(OutXML);

System.IO.FileStream fs = new System.IO.FileStream(OutXML,
System.IO.FileMode.Create);
System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(fs,
System.Text.Encoding.Unicode);
System.Xml.Xsl.XslTransform xslt = new
System.Xml.Xsl.XslTransform();
try
{
xslt.Load(XSL);
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.Write(ex.Message);
}
try
{
xslt.Transform(xpd, null, xtw, null);
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.Write(ex.Message);
}
}

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" version="1.0" encoding="utf-16"/>
<xsl:template match="/">
<xsl:processing-instruction
name="mso-application"><xsl:text>progid="Excel.Sheet"</xsl:text></xsl:processing-instruction>

<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
</ExcelWorkbook>
<Worksheet ss:Name="Sheet1">
<Table>
<Column/>
<Column/>
<Column/>
<Row>
<Cell><Data ss:Type="String">Order ID</Data></Cell>
<Cell><Data ss:Type="String">Product ID</Data></Cell>
<Cell><Data ss:Type="String">Unit Price</Data></Cell>
<Cell><Data ss:Type="String">Quantity</Data></Cell>
<Cell><Data ss:Type="String">Discount</Data></Cell>
<Cell><Data ss:Type="String">Total</Data></Cell>
</Row>
<xsl:for-each select="//Table">
<Row>
<Cell><Data ss:Type="String"><xsl:value-of
select="OrderID"/></Data></Cell>
<Cell><Data ss:Type="Number"><xsl:value-of
select="ProductID"/></Data></Cell>
<Cell><Data ss:Type="Number"><xsl:value-of
select="UnitPrice"/></Data></Cell>
<Cell><Data ss:Type="Number"><xsl:value-of
select="Quantity"/></Data></Cell>
<Cell><Data ss:Type="Number"><xsl:value-of
select="Discount"/></Data></Cell>
<Cell ss:Formula="=RC[-3]*RC[-2]*(1-RC[-1])"><Data
ss:Type="Number">0</Data></Cell>
</Row>
</xsl:for-each>
<Row>
<Cell/>
<Cell/>
<Cell/>
<Cell/>
<Cell/>
<Cell ss:Formula="=SUM(R2C:R[-1]C)"><Data
ss:Type="Number">0</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<Print>
<ValidPrinterInfo/>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<Selected/>
<DoNotDisplayGridlines/>
<FreezePanes/>
<FrozenNoSplit/>
<SplitHorizontal>1</SplitHorizontal>
<TopRowBottomPane>1</TopRowBottomPane>
<ActivePane>2</ActivePane>
<Panes>
<Pane>
<Number>3</Number>
</Pane>
<Pane>
<Number>2</Number>
<ActiveRow>0</ActiveRow>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>

Nov 12 '05 #1
1 1333
"George1776" <ge*********@yahoo.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com...
final XML document does not include an xml declaration (i.e. <?xml
version="1.0"?>). : : System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter( fs, System.Text.Encoding.Unicode); : :

Insert the following statement here,

xtw.WriteStartDocument( );

: : System.Xml.Xsl.XslTransform xslt = new System.Xml.Xsl.XslTransform( );

: :
Derek Harmon
Nov 12 '05 #2

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

Similar topics

0
by: anonymous | last post by:
I cannot compile LiDIA mathematical library version 2.1pre5 with the gmp 4.1.2 multiprecision library because the gcc compiler ver 3.2.2 20030222 Red Hat Linux 9 complains about some structures in...
11
by: Jian H. Li | last post by:
Hello, As a beginner to C++, I need Your kind help to clarify the basic concept. The sample C++ code as following: int i; // A i++; // B, error int main() {
1
by: MK | last post by:
I need div two big int. I use this lib: https://sourceforge.net/projects/cpp-bigint/ I create simple project and include two file bigint.h and bigint.cpp (Precompiled headers is not using) When...
2
by: Donna Sabol | last post by:
Maybe it's not me. I posted a question earlier about not getting a function call right. Well, now I'm trying to write some very simple code, and I can't get ANYTHING to work. It won't even...
10
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...
25
by: venky | last post by:
Hi main() { int x; /* it declaration or defination??*/ }
4
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
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...
6
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...
10
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.