473,587 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 OleDbDataAdapte r, 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 1773
"johnb41" <or****@informa tik.com> wrote in message news:11******** **************@ f14g2000cwb.goo glegroups.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 programmaticall y,

DataTable table = new DataTable( "Orders");

Then add columns to it,

table.Columns.A dd( new DataColumn( "Order", typeof(string)) );
table.Columns.A dd( 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.Att ribute;

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( "Fulfillmen t");
dataSet1.Tables .Add( table);

DataView view = dataSet1.Defaul tViewManager.Cr eateView( 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.rowfil ter: 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****@informa tik.com> wrote in message news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Quick question about dataview.rowfil ter: 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.Dat a" 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
3145
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 existing dataset.cs file that can be visually manipulated in the VS.NET Dataset Designer wizard in VS.NET 2003 with .NET 1.1 and C#. Here is the issue...
0
3629
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 datagrid on the left side that lists names and perhaps a couple of other key fields. The user can click on a record in the datagrid, which should...
0
894
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
2239
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 each row needs a <textarea> control. The background supporting classes are completed, the only task left now is to create the web page. I am at a...
7
5463
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 loop through the filtered GridView to identify the selected rows and assemble some XML to be sent to a stored proc. The problem I have is that when...
0
1132
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 functionality should be that the user selects a distinct value from the first cb, the other 2 are filtered by that value selected, the user selects the...
3
1747
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 this. Thanks KES -- thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
0
1950
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 DataGridView controls show filtered data of the DataSet. Using the Visual Studio 2005 designer, I have generated RDLC file with report tables and a Form...
1
1200
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 be spelled a little differently or some of the data might be inaccurate. It is hard to think of any user interface that would allow this, but I'm...
0
7918
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8206
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5713
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.