471,330 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

generate xml document

Hello!

Is possible to generate an xml document in any way or is the only way to
write it manually.
We can assume that we have all the information for the xml document.

//Tony
Aug 13 '08 #1
7 1222
Lots of ways... how do you currently have the data, and what is it?
That will determine the most suitable option.

Marc
Aug 13 '08 #2
On Aug 13, 10:47*am, Marc Gravell <marc.grav...@gmail.comwrote:
Lots of ways... how do you currently have the data, and what is it?
That will determine the most suitable option.
And also, which version of the framework are you using? LINQ to XML is
lovely, but only if you're using .NET 3.5...

Jon
Aug 13 '08 #3
And also, which version of the framework are you using? LINQ to XML is
lovely, but only if you're using .NET 3.5...
And where is the data coming from... for example, SQL/XML in SQL
Server 2005 / 2008 can work very well via "FOR XML PATH" in TSQL.

Marc
Aug 13 '08 #4
Hello!

Assume I have SQL server 2005 database where I want some data to be inserted
into a Xml document.
//Tony

"Marc Gravell" <ma**********@gmail.comskrev i meddelandet
news:9d**********************************@y38g2000 hsy.googlegroups.com...
And also, which version of the framework are you using? LINQ to XML is
lovely, but only if you're using .NET 3.5...

And where is the data coming from... for example, SQL/XML in SQL
Server 2005 / 2008 can work very well via "FOR XML PATH" in TSQL.

Marc

Aug 13 '08 #5
Again, that doesn't give much away... if you are talking about small
changes to xml *already stored in an xml column*, then you can do this
at the server in TSQL (see link below) and avoid the IO cost of moving
the data. If you want to get data *out* of the SQL Server as xml, then
"FOR XML PATH" is your friend. Neither of these involve C#, so I won't
go into detail here...

If you are reading simple data from the server (perhaps via LINQ-to-
SQL) then you might want to do some work in C# - but as Jon correctly
observes, this depends on which framework you are using. With 2.0/3.0
you have XmlDocument and XmlWriter, but 3.5 introduces XDocument and
some language enhancements which make it trivial to construct xml in
various shapes.

Perhaps a simpified (but concrete) example would make things
clearer...? Can you explain more what you want to happen?

TSQL/XML link: http://msdn.microsoft.com/en-us/library/ms345117.aspx

Marc
Aug 13 '08 #6
Hello!

I just trying to learn some basic Xml so I have no specific task that I want
to accomplish.

//Tony

"Marc Gravell" <ma**********@gmail.comskrev i meddelandet
news:48**********************************@34g2000h sh.googlegroups.com...
Again, that doesn't give much away... if you are talking about small
changes to xml *already stored in an xml column*, then you can do this
at the server in TSQL (see link below) and avoid the IO cost of moving
the data. If you want to get data *out* of the SQL Server as xml, then
"FOR XML PATH" is your friend. Neither of these involve C#, so I won't
go into detail here...

If you are reading simple data from the server (perhaps via LINQ-to-
SQL) then you might want to do some work in C# - but as Jon correctly
observes, this depends on which framework you are using. With 2.0/3.0
you have XmlDocument and XmlWriter, but 3.5 introduces XDocument and
some language enhancements which make it trivial to construct xml in
various shapes.

Perhaps a simpified (but concrete) example would make things
clearer...? Can you explain more what you want to happen?

TSQL/XML link: http://msdn.microsoft.com/en-us/library/ms345117.aspx

Marc

Aug 13 '08 #7
Then here's a very simple LINQ-to-XML example; anything more really
needs a specific question...

Marc

var data = new[] {
new {Name = "Fred", Age = 25},
new {Name = "Jo", Age = 11},
new {Name = "Sally", Age = 41}
};

var doc = new XDocument(
new XElement("xml",
new XAttribute("created", DateTime.Today),
from person in data
select new XElement("person",
new XAttribute("name", person.Name),
new XAttribute("age", person.Age))));

string xml = doc.ToString();
Aug 13 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Dario de Judicibus | last post: by
2 posts views Thread by soundarya | last post: by
2 posts views Thread by Delmar | last post: by
5 posts views Thread by =?Utf-8?B?a3Jpcw==?= | last post: by
21 posts views Thread by Grant Edwards | last post: by

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.