468,733 Members | 1,338 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

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 2182
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Sadun Sevingen | last post: by
3 posts views Thread by MDB | last post: by
1 post views Thread by Adam Knight | last post: by
3 posts views Thread by filip.norrgard | last post: by
5 posts views Thread by sql_er | last post: by
4 posts views Thread by Andy B | last post: by
1 post views Thread by CARIGAR | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.