472,780 Members | 4,650 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Querying a dataset filled from XML file

I have a simple application that uses an XML file to store it's data. That
means I don't have a seperate database. In order to read the data I created a
DataSet that reads my XML file with the .ReadXml() method.

1.
I want to manipulate the resulting dataset, preferably with SQL queries. But
the documentation states that I need to have a data connection to do this.
But if I am only using an XML file, how do I do this without a data
connection?

2.
When I fill the dataset I have no trouble reading the column names, but how
do I read the attributes? For instance, this is a portion of my XML file:

<partyList xmlns="http://tempuri.org/DataSchema.xsd">
<party xmlns="http://tempuri.org/DataSchema.xsd">
<Name>CDA</Name>
<Leader>
<Name>J.P. Balkenende</Name>
</Leader>
</Name>
</party>
</partyList>

To read the Party Name I use dsParties.Tables("Party").Rows(0).Item("Name"),
but how do I access the Leader Name ?

Any help on these 2 questions would be appreciated!
-Chris
Nov 12 '05 #1
3 2269
"C. Hughes" <C. Hu****@discussions.microsoft.com> schrieb
1.
I want to manipulate the resulting dataset, preferably with SQL queries. But the documentation states that I need to have a data connection to do this.
But if I am only using an XML file, how do I do this without a data
connection?
you can't modify a DataSet with SQL queries. You can only fill it by an
SqlCommand or DataAdapter which uses SQL queries and a data connection to
get data from a database.
If you want to filter the data of a DataSet, you can use DataViews.

2.
When I fill the dataset I have no trouble reading the column names, but how do I read the attributes? For instance, this is a portion of my XML file:

<partyList xmlns="http://tempuri.org/DataSchema.xsd">
<party>
<Name>CDA</Name>
<Leader>
<Name>J.P. Balkenende</Name>
</Leader>
</Name>
</party>
</partyList>

To read the Party Name I use dsParties.Tables("Party").Rows(0).Item("Name"), but how do I access the Leader Name ?


dsParties.Tables("Leader").Rows(0).Item("Name")
(Remark: Leader is not an attribut, it is an element)

Or if you have set the DataRelation between the Tables "Party" and "Leader"
(in C#):
dsParties.Tables["Party"].Rows[0].GetChildRows(relationPartyLeader)[0]["Name
"]

Roughly: Elements (with complex type) will be readed as a table, and
Attributes (and Elements with simple type) as columns to the Element-tables.

Jaga

Nov 12 '05 #2
Hi Jaga,

Thanks for your reply. It has helped me, but there is one thing is still
don't understand.

If in my previous example "Leader" is loaded as a seperate table to "Party",
then how do I maintain a relation between these two? If I were to extend the
XML file so that each Party could have N number of leaders then how do i
still know which leader belongs to which party ?
Nov 12 '05 #3
"C. Hughes" <CH*****@discussions.microsoft.com> wrote
If in my previous example "Leader" is loaded as a seperate table to "Party", then how do I maintain a relation between these two? If I were to extend the XML file so that each Party could have N number of leaders then how do i
still know which leader belongs to which party ?


Both tables ("Party" and "Leader") receives a column "Party_Id" with the
attribute ColumnMapping=Hidden.
Each Party receives an unique Party_Id and each Leader receives the Party_Id
of his Party.
The DataSet receives a DataRelation "Party_Leader" between the columns
Party.Party_Id and Leader.Party_Id.

Jaga

Nov 12 '05 #4

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

Similar topics

5
by: Sadun Sevingen | last post by:
hi i get dataset from'an webservice so i don't have an adaptor... dataset's structure is same as mine database table.... how can i update database table according to dataset...
1
by: Johann Blake | last post by:
I have a dataset that contains a parent table and a child table. A DataRelation exists between the two. I was under the impression from reading the VS docs that when I filled the parent table, the...
3
by: MDB | last post by:
I'd normally Google for a question like this, and hope to snag a few examples along with the answer, but this time I can't see to get the keywords specific enough. Or I'd ask coworkers, but...
1
by: Adam Knight | last post by:
Hi all, A couple of quick questions relating to datasets: Is one dataset in a given page generally used to bind all controls to db data? If a dataset object is to be used globally by all,...
2
by: Jeff Brown | last post by:
OK i have came to the conclusion that since this app will be run on multiple computers that loading a complete database and then updating on exit is a moot point. I have tried several ideas...
3
by: filip.norrgard | last post by:
Hi All! I've been developing an ASP.Net 2.0 web application using the Visual Studio 2005 tools. Currently datagrids on a page are filled with data from a dataset (a .xsd file in the "project")...
5
by: sql_er | last post by:
Guys, I have an XML file which is 233MB in size. It was created by loading 6 tables from an sql server database into a dataset object and then writing out the contents from this dataset into an...
2
by: darrel | last post by:
We have a home grown web site. We store page information, including a time-stamp as to when it was last updated in a database table. We also store the site architecture (navigation) in an XML...
4
by: Andy B | last post by:
I have a wizard on a page that will dynamically create a dataset as it goes along based on user input. When the wizard is done, it will dump all of the data it collected/created in the wizard to an...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.