473,587 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(o bject sender, System.EventArg s e)
{
string s = "SELECT TOP 10 * FROM [Order Details]";
string OutXML = @"C:\Documen ts and Settings\gbarke r\My
Documents\Excel XMLTest\Orders. xml";
string XSL = @"C:\Documen ts and Settings\gbarke r\My
Documents\Excel XMLTest\Orders. xsl";

System.Data.Sql Client.SqlConne ction cn = new
System.Data.Sql Client.SqlConne ction("Server=W IN2KDEV1;Databa se=Northwind;US ER
ID=SA;Password= password");
System.Data.Sql Client.SqlComma nd cmd = new
System.Data.Sql Client.SqlComma nd(s, cn);
cn.Open();
System.Data.Dat aTable dt = new DataTable();
System.Data.Dat aSet ds = new DataSet();
System.Data.Sql Client.SqlDataA dapter da = new
System.Data.Sql Client.SqlDataA dapter();
da.SelectComman d = cmd;
da.Fill(ds);
cn.Close();

ds.WriteXml(Out XML);

System.Xml.XPat h.XPathDocument xpd = new
System.Xml.XPat h.XPathDocument (OutXML);

System.IO.FileS tream fs = new System.IO.FileS tream(OutXML,
System.IO.FileM ode.Create);
System.Xml.XmlT extWriter xtw = new System.Xml.XmlT extWriter(fs,
System.Text.Enc oding.Unicode);
System.Xml.Xsl. XslTransform xslt = new
System.Xml.Xsl. XslTransform();
try
{
xslt.Load(XSL);
}
catch (System.Excepti on ex)
{
System.Diagnost ics.Debug.Write (ex.Message);
}
try
{
xslt.Transform( xpd, null, xtw, null);
}
catch (System.Excepti on ex)
{
System.Diagnost ics.Debug.Write (ex.Message);
}
}

<?xml version="1.0"?>
<xsl:styleshe et 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:processi ng-instruction
name="mso-application"><x sl:text>progid= "Excel.Shee t"</xsl:text></xsl:processing-instruction>

<Workbook xmlns="urn:sche mas-microsoft-com:office:spre adsheet"
xmlns:o="urn:sc hemas-microsoft-com:office:offi ce"
xmlns:x="urn:sc hemas-microsoft-com:office:exce l"
xmlns:ss="urn:s chemas-microsoft-com:office:spre adsheet"
xmlns:html="htt p://www.w3.org/TR/REC-html40">
<ExcelWorkboo k xmlns="urn:sche mas-microsoft-com:office:exce l">
</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:valu e-of
select="OrderID "/></Data></Cell>
<Cell><Data ss:Type="Number "><xsl:valu e-of
select="Product ID"/></Data></Cell>
<Cell><Data ss:Type="Number "><xsl:valu e-of
select="UnitPri ce"/></Data></Cell>
<Cell><Data ss:Type="Number "><xsl:valu e-of
select="Quantit y"/></Data></Cell>
<Cell><Data ss:Type="Number "><xsl:valu e-of
select="Discoun t"/></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="=SU M(R2C:R[-1]C)"><Data
ss:Type="Number ">0</Data></Cell>
</Row>
</Table>
<WorksheetOptio ns xmlns="urn:sche mas-microsoft-com:office:exce l">
<Print>
<ValidPrinterIn fo/>
<HorizontalReso lution>600</HorizontalResol ution>
<VerticalResolu tion>600</VerticalResolut ion>
</Print>
<Selected/>
<DoNotDisplayGr idlines/>
<FreezePanes/>
<FrozenNoSpli t/>
<SplitHorizonta l>1</SplitHorizontal >
<TopRowBottomPa ne>1</TopRowBottomPan e>
<ActivePane>2 </ActivePane>
<Panes>
<Pane>
<Number>3</Number>
</Pane>
<Pane>
<Number>2</Number>
<ActiveRow>0</ActiveRow>
</Pane>
</Panes>
<ProtectObjects >False</ProtectObjects>
<ProtectScenari os>False</ProtectScenario s>
</WorksheetOption s>
</Worksheet>
</Workbook>
</xsl:template>
</xsl:stylesheet>

Nov 12 '05 #1
1 1348
"George1776 " <ge*********@ya hoo.com> wrote in message news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
final XML document does not include an xml declaration (i.e. <?xml
version="1.0"?> ). : : System.Xml.XmlT extWriter xtw = new System.Xml.XmlT extWriter( fs, System.Text.Enc oding.Unicode); : :

Insert the following statement here,

xtw.WriteStartD ocument( );

: : 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
1800
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 the gmp.h header file: /usr/local/include/gmp.h:2073: declaration of C function `std::ostream& operator<<(std::ostream&, const __mpq_struct*)'...
11
10744
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
3987
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 I try build I get: Why? Help. :--------------------Configuration: av - Win32 Debug-------------------- Compiling...
2
2298
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 display a simple message box... Same form I had in my previous post. It's got about 10 fields on it. It is linked right to the table containing the...
10
20849
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 setting aside storage for an object, defining/declaring a struct, parts of a function, referencing an external variable in another module. ...
25
2784
by: venky | last post by:
Hi main() { int x; /* it declaration or defination??*/ }
4
6100
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
8870
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 *defined* "x"'s value to be 10, isn't above statement a
6
3158
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 void func()
10
4326
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 in Linux with GCC. pthread_cond_signal(&(receiverConf->receive_q_cond)); pthread_cond_destroy(&(receiverConf->receive_q_cond));...
0
7852
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8349
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.