By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,169 Members | 1,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,169 IT Pros & Developers. It's quick & easy.

filtering an XML Dataset

P: n/a
Hi,

I use the ReadXML method in my C# Windows Form project.
Here is some of my C# code:
xmlDS.ReadXml(curDir + "\\Dept.xml") ;

There're 20 rows and 5 columns in the Dept.xml.
But now I just want some of the data in the Dept.xml, e.g., DeptLevel >1 AND
Status=0.
How do I filter the XML or xmlDS so that the output is what I need?
Thanks for help.
Jason
Mar 30 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
You need to understand DataSets better, and the difference between a
serialized class and the class itself. The XML file you're talking about is
an XML document. When you create a DataSet and read from the file to
populate it, you are no longer dealing with XML; you're dealing with a
DataSet. An XML document doesn't have columns and rows; it has nodes. A
DataSet doesn't have columns and rows either; it has Tables (DataTables) and
schema information about the data and the tables. A DataTable can not be
filtered. But when you use a DataTable, you generally work with a DataView
rather then the table itself. Now, a DataView can be filtered, sorted, and
manipulated in a variety of ways. For more information, see:

http://msdn.microsoft.com/library/de...xmldataset.asp
http://msdn.microsoft.com/library/de...ngdatasets.asp
http://msdn.microsoft.com/library/en...asp?frame=true
http://msdn.microsoft.com/library/en...asp?frame=true

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Jason Huang" <Ja************@hotmail.com> wrote in message
news:u9**************@TK2MSFTNGP14.phx.gbl...
Hi,

I use the ReadXML method in my C# Windows Form project.
Here is some of my C# code:
xmlDS.ReadXml(curDir + "\\Dept.xml") ;

There're 20 rows and 5 columns in the Dept.xml.
But now I just want some of the data in the Dept.xml, e.g., DeptLevel >1
AND Status=0.
How do I filter the XML or xmlDS so that the output is what I need?
Thanks for help.
Jason

Mar 30 '06 #2

P: n/a

"Jason Huang" <Ja************@hotmail.com> wrote in message
news:u9**************@TK2MSFTNGP14.phx.gbl...
Hi,

I use the ReadXML method in my C# Windows Form project.
Here is some of my C# code:
xmlDS.ReadXml(curDir + "\\Dept.xml") ;

There're 20 rows and 5 columns in the Dept.xml.
But now I just want some of the data in the Dept.xml, e.g., DeptLevel >1
AND Status=0.
How do I filter the XML or xmlDS so that the output is what I need?
Thanks for help.


Your best bet is probably just to use a DataView.

If you really want to filter the data coming into the dataset then either

use a DataView to do the filtering and copy it into another dataset

OR create your own class derived from XmlReader to do the filtering and pass
it to the overload of ReadXml. This reader should be quite simple as it just
has to filter the output of an XmlTextReader which will actually read the
file.
Mar 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.