Write to an XML file using data from an SQLserver table

B

Bill Nguyen

I wonder if I can write to an XML file using column structure (and column
names) of an SQLserver table.

for example:
Table A:
column1 int
column2 char(30)
column3 date

XML output:

<column1>12</column1>
<column2>my first XML Doc</column2>
<column3>06/15/2006</column3>


Any help is greatly appreciated.

Bill
 
C

Cor Ligthert [MVP]

Bill,

This is very simple, assuming it is a table from version 2003 than

dim ds a new dataset
ds.Add(theSQLTable)
ds.WriteXML("thePath",SeeTheIntelicenceForTheSchema)

While in 2005 even
theSQLTable.WriteXml(see above

I hope this helps,

Cor
 
B

Bill Nguyen

Cor;
Thanks a million!

I found another answer using XSLT. However , I had problem incorporating the
file into my application (NET 2.0).
I added it as an xslt document to the project, but don't know how to use it
to transorm the xml output doc.

Any help is greatly appreciated.

Bill


XSLT filename: myStylesheet.xslt

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:blush:utput method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="sqlData">
<foo>
<INFO></INFO>
<DATA>
<xsl:copy-of select="*"/>
</DATA>
</foo>
</xsl:template>

</xsl:stylesheet>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top