Groups | Blog | Home
all groups > dotnet xml > october 2003 >

dotnet xml : Creating XML from a DB


Dino Chiesa [Microsoft]
10/27/2003 6:22:36 PM
Are you using SQL Server? if so, there is a FOR XML syntax that can do
this.
http://www.microsoft.com/mspress/books/sampchap/5178c.asp

Other databases have similar support for producing XML from queries, but it
varies.

-Dino

--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m


[quoted text, click to view]

Shawn
10/27/2003 8:15:17 PM
I have two simple tables in my DB: "person" and "phone". Person has 3
fields: id, fistname and lastname. Phone has two fields: id and phonenumber.
Each person can have many phonenumbers. I wish to create an xml file out of
the two tables. Something like this:
<user>
<id>1</id>
<firstname>John</firstname>
<lastname>Doe</lastname>
<phone>
<phonenumber>5550001</phonenumber>
<phonenumber>5550002</phonenumber>
<phonenumber>5550003</phonenumber>
</phone>
</user>

How can I achieve this?
any help is greatly appreciated!

Shawn

Shawn
10/28/2003 8:27:07 AM
I'm using a Sybase DB. I know Sybase can produce XML, but I was told I had
to do it through code. Any ideas?

Shawn


[quoted text, click to view]
Are you using SQL Server? if so, there is a FOR XML syntax that can do
this.
http://www.microsoft.com/mspress/books/sampchap/5178c.asp

Other databases have similar support for producing XML from queries, but it
varies.

-Dino

--
Dino Chiesa
Microsoft Developer Division
d i n o c h @ o n l i n e . m i c r o s o f t . c o m


[quoted text, click to view]


Robert Rossney
10/28/2003 9:01:45 AM
[quoted text, click to view]
: I'm using a Sybase DB. I know Sybase can produce XML, but I was told I
had
: to do it through code. Any ideas?

If you're using ADO to access the database, you can use the Recordset
object's Save method to persist a recordset as an XML document.

Bob Rossney
rbr@well.com

Dino Chiesa [Microsoft]
10/28/2003 11:23:07 AM
Also, if you are using ADO.NET, you can also use the WriteXml method on the
DataSet instance. The issue with either of these approaches (with ADO and
with ADO.NET) is that you don't have a great deal of control over the
"shape" of the XML. You get the recordset schema, or the dataset schema,
respectively. With the "FOR XML" support in sQL Server, you, the
programmer, have control over the XML Schema - the shape of the output XML.
The same is true for other databases' special support for XML, but I am not
an expert in Sybase or IBM or Oracle, so i cannot comment on particulars. I
believe they all do something similar.

-Dino



[quoted text, click to view]

AddThis Social Bookmark Button