473,398 Members | 2,088 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,398 software developers and data experts.

xml instead db

mp
Hi,

How we can use xml file instead data base table (read/write).

Example:
CustID | FirstName | lastName | etc.

I am looking for some example.

Thanks
Nov 16 '05 #1
1 1692
Hi,

What are you intending to do? Use ADO.NET with out a db backend?

If so, you will have to build the tables,relationships and dataset using
code, after that you can use the same way to query the dataset
after than yuo can serialize the dataset to a XML file and later load it
back.

Here is some code that can help you with it.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

********************Loading the data ********************

if ( File.Exists( reportfile) )
{
LoadReportData();
}
else
{
CreateReportDS();
}

void LoadReportData()
{
reports = new DataSet();
StreamReader stream = new StreamReader(reportfile);
XmlTextReader reader = new XmlTextReader(stream);
reports.ReadXml(reader, XmlReadMode.ReadSchema);
reader.Close();
stream.Close();
}

************ Creating the data ********************

static void CreateReportDS()
{
reports = new DataSet("Reports");

#region The Report table
DataTable table = new DataTable("Report");
DataColumn pkCol = table.Columns.Add("ID", typeof(int));
pkCol.AutoIncrementSeed=0;
pkCol.AutoIncrement = true;
table.Columns.Add("Location", typeof(string));
table.Columns.Add("Exported", typeof(bool));
table.PrimaryKey = new DataColumn[] {pkCol};
reports.Tables.Add( table);
#endregion

#region The Answer Table
table = new DataTable("Answer");
pkCol = table.Columns.Add("ID", typeof(int));
pkCol.AutoIncrement = true;
pkCol.AutoIncrementSeed = 1;
table.Columns.Add("answer", typeof(char));
table.Columns.Add("comments", typeof(string));
table.PrimaryKey = new DataColumn[] {pkCol};
reports.Tables.Add( table);
#endregion

#region The ReportAnswer Report Relationship
DataRelation fkRel = new DataRelation( "Report_Answer",
reports.Tables["Report"].Columns["ID"],
reports.Tables["Answer"].Columns["rID"]);
reports.Relations.Add( fkRel);
#endregion

}
******************** Saving the data ********************

StreamWriter stream = new StreamWriter( reportfile);
XmlTextWriter writer = new XmlTextWriter(stream);
reports.WriteXml( writer, XmlWriteMode.WriteSchema);
writer.Close();
stream.Close();
"mp" <pl****@volja.net> wrote in message
news:OH**************@TK2MSFTNGP10.phx.gbl...
Hi,

How we can use xml file instead data base table (read/write).

Example:
CustID | FirstName | lastName | etc.

I am looking for some example.

Thanks

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Aardwolf | last post by:
I've had PHP on my Win2K server running IIs 5 for about 2 weeks now. I have an annoying problem in that I can not run the php scripts/pages locally, instead they open up in the browser as a...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
8
by: joe | last post by:
hi i am trying to write a insted of insert trigger to create a unique id when i insert a record in my database. can anyone give me an example with out using identity. thanks
3
by: cfxchange | last post by:
I am looking into work-arounds for what seems to be a flaw, or "undocumented feature" of SQL Server replication and Instead of Delete triggers not playing together. It seems that if you want to...
8
by: Stuart McGraw | last post by:
Is Microsoft full of #*$#*% (again) or am I badly misunderstanding something? Quote from Microsoft's T-SQL doc: > INSTEAD OF triggers are executed instead of the triggering action. > These...
5
by: Chris | last post by:
I'm attempting to get Instead Of triggers working. My platform in Solaris, DB2 verison 8.1.x (not sure which). If I create two simple tables with 1 row each: create table test_cc_1 (col1...
25
by: dixie | last post by:
I have some code that adds new records into a table for each ID in a list box when a button on a form is clicked. This works fine. My problem now is that I wish to be able to edit all the records...
4
by: Mark Reed | last post by:
Hi all, I have the following code which imports the contents of all files within a set folder which works excellently. Once it has imported from each file, it deletes the file. Is there a way that...
4
by: Jim Hammond | last post by:
It would be udeful to be able to get the current on-screen values from a FormView that is databound to an ObjectDataSource by using a callback instead of a postback. For example: public void...
12
by: comp.lang.php | last post by:
I am using CLI PHP to run a PHP script, c:\wamp\php\php.exe, but instead of executing my script, it's actually displaying the raw code instead. How can I run my code using CLI PHP? I installed...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.