473,320 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

creating xml file

hi,

I am creating xml file like this

cn = new OleDbConnection(CONN_STRING);
da = new OleDbDataAdapter("select satisfactoryitemcount as ConsumerRating from inspection where InspectorperiodId=4147 Order by CreatedDateTime ASC", cn);
DataSet Inspection = new DataSet("InspectionSummaryReport");
da.Fill(Inspection);
Inspection.WriteXml("C:\\aa.xml");

it working fine and i am getting the output like this

<?xml version="1.0" standalone="yes"?>
<InspectionSummaryReport>
<Table>
<ConsumerRating>0</ConsumerRating>
</Table>
</InspectionSummaryReport>

but i want out put like

<?xml version="1.0" standalone="yes"?>
<InspectionSummaryReport>
<ConsumerRating>0</ConsumerRating>
</InspectionSummaryReport>

That is i dont want table tag.Any one help me urgent plz.

Regards,
Koti.
Mar 21 '08 #1
1 1107
balabaster
797 Expert 512MB
The common misconception about datasets is that they mimic the behaviour of recordsets which only held a single table of data. DataSets now are more like an "off-line" (I say off-line, but it may be connected or disconnected) version of your relational database... what I mean to say is that the layout of your data in your DataSet is a relational model - the DataSet is a shell as it were containing your table(s) of data in a hierarchical fashion

DataSet
|-Table
| |-DataRow0
| | |-DataColumn0
| | \-DataColumn1
etc

So when you export using the WriteXML method, the entire DataSet is exported to XML, including all tables, relationships, keys etc. You need to export just the relevant DataTable - The DataTable class (which can be filled using the DataAdapter in the same manner as a DataSet) has the same WriteXML method - however, this still isn't in quite the correct format, you would need an XSLT (XML Stylesheet Language Transformation) to translate the resulting XML to the format you're looking for.

The simplest way to write the XML format you want is to create a string containing the XML and then write the string to a text file (of course, XSLT is a handy tool in your arsenal. Understanding how it works will pay dividends in the long run).

Expand|Select|Wrap|Line Numbers
  1. DataTableReader oDTR = oDS.Tables(0).CreateDataReader();
  2. StringBuilder sOut = new StringBuilder("<?xml version ""1.0"" standalone=""yes""?>");
  3. sOut.Append("<InspectionSummaryReports>");
  4. If(oDTR.HasRows){
  5.   While oDTR.Read{
  6.     sOut.Append("<Field1>" & oDTR(0) & "</Field1>");
  7.     // sOut.Append("<Field2>" & oDTR(1) & "</Field2>");
  8.     // etc.
  9.   }
  10. }
  11. sOut.Append("</InspectionSummaryReports>");
  12. System.IO.file.WriteAllText("Output.xml", sOut.ToString());
Mar 21 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: C-man | last post by:
Basically I have this little program that will look through directories and rename any file it finds. The renaming that takes place is like removing of dashes or Caps the first letter from each...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
5
by: Sam777 | last post by:
I was under the impression that creating the app_offline.htm file at the root of the webapp would cause all handles to be closed so that the app could be removed. Unfortunately, this isn't the...
15
by: David Thielen | last post by:
Hi; My ASP.NET app (C# calling J# under .net 2.0) creates a png file in a subdirectory to display as part of the created page. However, the bitmap will not display due to a security violation. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.