473,383 Members | 1,879 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,383 software developers and data experts.

Create filtered dataset from XML file?

I need to create a Dataset and datatable from an XML file. The only
way I know how to make a Dataset and Datatable, is by using an Access
database as my datastore: You know, the usual thing in all the books;
an OleDbDataAdapter, with a SQL string and connection.

How can I do this using an XML file instead of an Access table? I know
I can convert an XML file straight into a Dataset. But the dataset
always contains ALL the info from the XML file. I want the dataset to
be filtered by using some sort of query.

A couple years ago I hurt my brain figuring out Xpath. Boy, i'm just
not meant to understand it! Is Xpath what I'm supposed to use?

Can anyone shed some light on this for me?

Thanks!
John

Nov 12 '05 #1
4 1763
"johnb41" <or****@informatik.com> wrote in message news:11**********************@f14g2000cwb.googlegr oups.com...
The only way I know how to make a Dataset and Datatable, is by
using an Access database as my datastore:
Well, you can always create a DataTable programmatically,

DataTable table = new DataTable( "Orders");

Then add columns to it,

table.Columns.Add( new DataColumn( "Order", typeof(string)));
table.Columns.Add( new DataColumn( "ShipDate", typeof(DateTime)));

With the default deserialization logic, you can (to a limited extent) customize
what sorts of XML nodes these data columns are mapped from,

table.Columns[ "ShipDate"].ColumnMapping = MappingType.Attribute;

Then add rows to it,

table.Rows.Add( new object[] { "7-button mouse", new DateTime( 2005, 4, 18) } );
table.Rows.Add( new object[] { "red wagon", new DateTime( 2005, 3, 26) } );
I know I can convert an XML file straight into a Dataset. But the dataset
always contains ALL the info from the XML file. I want the dataset to
be filtered by using some sort of query.
Filtering this should be possible by writing a custom XmlTextReader that
strips out the content you don't want to pass through to DataSet.ReadXml( ).
How easy it is to write this custom XmlTextReader will vary proportionately
to the complexity of the queries you need to support. However, simple
filtration XmlTextReaders, like retrieve only the <Orders> where the
@ShipDate is within the past 30 days (and @ShipDate is an attribute
on Orders) are relatively simple to write.
A couple years ago I hurt my brain figuring out Xpath. Boy, i'm just
not meant to understand it! Is Xpath what I'm supposed to use?


If XPath causes you injury, then an XML approach to the problem
probably isn't your course of least resistance. Have you considered
loading all of the XML into the DataSet and then using a Row Filter
to strip out rows you don't want in a more SQL-like notation, for
instance,

DataSet dataSet1 = new DataSet( "Fulfillment");
dataSet1.Tables.Add( table);

DataView view = dataSet1.DefaultViewManager.CreateView( table);
view.RowFilter = "ShipDate > #04/01/2005#";
Derek Harmon
Nov 12 '05 #2
Derek,

Thanks for your help!

XML, for me, is very difficult. I can use it in only the simplest
ways. Anything more just makes my head spin w/ all the complexity.
Your first 2 solutions just seem way too out of my reach.

The Row Filter solution looks like a good idea for me. I've done this
before and it's really easy. I can't belive i didn't consider it for
this! My only problem about it is that it's probably not very
processor efficient; you have to always load an entire XML file to a
dataset before you filter it. But in my project, it would probably not
be a very big deal.

Quick question about dataview.rowfilter: Does the SQL-like syntax
support the keyword "Between", and "and". If so, this solution should
work well for the type of queries that I need to do.

Thanks for your help!

John

Nov 12 '05 #3
"johnb41" <or****@informatik.com> wrote in message news:11**********************@o13g2000cwo.googlegr oups.com...
Quick question about dataview.rowfilter: Does the SQL-like syntax
support the keyword "Between", and "and".


It supports the keyword And, that allows you to emulate Between:

ColumnName between 10 and 20

can be written without Between as,

ColumnName >= 10 and ColumnName <= 20

which works fine as a row filter.

The documentation on the expression syntax is tucked away in a far
corner of the SDK, look for the help page under the .NET Frame-
work's "Class Reference" section, "System.Data" namespace,
"DataColumn" class, "Expression" property.
Derek Harmon
Nov 12 '05 #4
Thanks Derek for all your help!

John

Nov 12 '05 #5

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

Similar topics

0
by: Babu Mannaravalappil | last post by:
Hi all, I apologize for posting this question on two groups. I did not know which one out of "XML" and "ADONET" groups, should I post this. I would like to create an xsd file out of an...
0
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a...
0
by: Simon Gorski | last post by:
Hello NG, how can I save a filtered dataset? I am using dataview and dataset, but with the function (dataset.WriteXml) I get not the filtered output! Thanxs Simon G.
8
by: ASP Yaboh | last post by:
I have an ArrayList of data gathered from a database. I want to create a web page from this data by creating a <table>, each cell in each row displays the appropriate data. One of those cells in...
7
by: Ken | last post by:
Hi All - I have a filtered GridView. This GridView has a check box in the first column. This check box is used to identify specific rows for delete operations. On the button click event I...
0
by: Benny | last post by:
I am trying to figure out the best way to create a filtering user control. I have 3 fields I am using and therefore have 3 combobox's that all need to display distinct values. The resulting...
3
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
What are the steps necessary to get the filtered count from datasource. If i have to move it into a table just to gat the count i'll do so, but i'm not sure what the steps are needed to accomplish...
0
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hello Gurus, I need to create a Microsoft Visual Studio 2005 report at runtime. I wrote a C# window application, that holds a DataSet and several DataGridView controls. Each of the...
1
by: COHENMARVIN | last post by:
I have a programming problem - I'm supposed to take a gridview listing people, and then link from one row to another to indicate that the people are the same (if they are), even though the name may...
1
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: 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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.