Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2003

Tip: Looking for answers? Try searching our database.

Creating XML from a DB

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shawn - 27 Oct 2003 20:15 GMT
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
Dino Chiesa [Microsoft] - 28 Oct 2003 00:22 GMT
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

Signature

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

> 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.
[quoted text clipped - 15 lines]
>
> Shawn
Shawn - 28 Oct 2003 08:27 GMT
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

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

Signature

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

> 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>
[quoted text clipped - 12 lines]
>
> Shawn
Robert Rossney - 28 Oct 2003 17:01 GMT
: 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] - 28 Oct 2003 17:23 GMT
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

> : I'm using a Sybase DB.  I know Sybase can produce XML, but I was told I
> had
[quoted text clipped - 5 lines]
> Bob Rossney
> rbr@well.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.