473,486 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

I'm wondering if this would be the proper application of XML, XSD and a datagrid

Hi I'm James Newbie

I'm going to use some xml from a previous posters because it's similiar to
mine

<Store>
<Name> My Book Store</Name>
<Phone> 555-555-5555 </Phone>
<Book id="1" >
<Title>Thermodynamics Unleashed</Title>
<Price>56.00</Price>
</Book>
<Book id="2" >
<Title>CAD CAM</Title>
<Price>72.00</Price>
</Book>
<Book id="3" >
<Title>Machine Design</Title>
<Price>56.00</Price>
</Book>
</Store>
I was thinking of this instead

<Store>
<Name> My Book Store</Name>
<Phone> 555-555-5555 </Phone>
<Books>
<Book id="1" >
<Title>Thermodynamics Unleashed</Title>
<Price>56.00</Price>
</Book>
<Book id="2" >
<Title>CAD CAM</Title>
<Price>72.00</Price>
</Book>
<Book id="3" >
<Title>Machine Design</Title>
<Price>56.00</Price>
</Book>
</Books>
</Store>

Actually I was also thinking of this and the only advantage I can see (which
may not be one) is that when reading from an XMLDocument I can grab the
entire Books node and do what I need to.

I'm starting to read about reading XML into a dataset using a schema and I'm
not sure how this example can work. When I think about a dataset I'm
thinking a big square shaped structure with rows and columns. Now the above
xml is not square so first that confuses me and I think this is where the
schema comes into play.

Does the schema assist the data set and say for example put the Name and
Phone over here and then take all the books and keep them in a table? If
that is true would I be able to have a form that has two edit boxes, one for
Name and the other for Phone then a separate datagrid which would list all
the books?

Any answers, thoughts, examples or otherwise are highly appreciated!!! I'm
reading about all of this and the examples say this is how you read an xml
file and this is how you read a schema but I'm not seeing some of the
details.

Thanks alot!!!
James

Nov 16 '05 #1
3 1155
While this does lend itself to a relational database model, it's also a
perfectly acceptable XML design.

For a Microsoft DataSet, I'd actually opt for version one. It will be
easier to manipulate in code. If you plan on having more than one
store, I'd try something like this:

<Stores>
<Store Name="My Book Store">
<Phone>555-555-5555</Phone>
<Book book_id="1"><Title>Thermodynamics
Unleashed</Title><Price>56.00</Price></Book>
<Book book_id="2"><Title>CAD
CAM</Title><Price>72.00</Price></Book>
<Book book_id="3"><Title>Machine
Design</Title><Price>56.00</Price></Book>
</Store>
</Stores>

If there's really only one store, this might work better for you:
<Store>
<StoreInfo>
<Name>My Book Store</Name>
<Phone>555-555-5555</Phone>
</StoreInfo>
<Book book_id="1"><Title>Thermodynamics
Unleashed</Title><Price>56.00</Price></Book>
<Book book_id="2"><Title>CAD CAM</Title><Price>72.00</Price></Book>
<Book book_id="3"><Title>Machine
Design</Title><Price>56.00</Price></Book>
</Store>

Once you have your design the way you like it, use xsd.exe to make an
instant xsd from it, e.g.
xsd store.xml ( produces store.xsd, all read to go in a VS.NET project
) More info here:
http://msdn.microsoft.com/library/de...ToolXsdexe.asp

Fire up VS.NET ( which I'm hoping you have, else run and get C#
Express, it's a good IDE and free while in beta ). In your project,
include your .xsd. In the visual thing, tell it book_id is the primary
key of book. Of you don't have this toy, the following in the DataSet
element of source will do the same: <xs:unique name="BookKey1"
msdata:PrimaryKey="true"><xs:selector xpath=".//Book" /><xs:field
xpath="@book_id" /></xs:unique>

Now, when you play with your typed DataSet, you should be able to do
something like dataSet.Book.FindBybook_id(2) to grab specific book.

Hope this helps,
Brett

James wrote:
Hi I'm James Newbie

I'm going to use some xml from a previous posters because it's similiar to mine

<Store>
<Name> My Book Store</Name>
<Phone> 555-555-5555 </Phone>
<Book id="1" >
<Title>Thermodynamics Unleashed</Title>
<Price>56.00</Price>
</Book>
<Book id="2" >
<Title>CAD CAM</Title>
<Price>72.00</Price>
</Book>
<Book id="3" >
<Title>Machine Design</Title>
<Price>56.00</Price>
</Book>
</Store>
I was thinking of this instead

<Store>
<Name> My Book Store</Name>
<Phone> 555-555-5555 </Phone>
<Books>
<Book id="1" >
<Title>Thermodynamics Unleashed</Title>
<Price>56.00</Price>
</Book>
<Book id="2" >
<Title>CAD CAM</Title>
<Price>72.00</Price>
</Book>
<Book id="3" >
<Title>Machine Design</Title>
<Price>56.00</Price>
</Book>
</Books>
</Store>

Actually I was also thinking of this and the only advantage I can see (which may not be one) is that when reading from an XMLDocument I can grab the entire Books node and do what I need to.

I'm starting to read about reading XML into a dataset using a schema and I'm not sure how this example can work. When I think about a dataset I'm
thinking a big square shaped structure with rows and columns. Now the above xml is not square so first that confuses me and I think this is where the schema comes into play.

Does the schema assist the data set and say for example put the Name and Phone over here and then take all the books and keep them in a table? If that is true would I be able to have a form that has two edit boxes, one for Name and the other for Phone then a separate datagrid which would list all the books?

Any answers, thoughts, examples or otherwise are highly appreciated!!! I'm reading about all of this and the examples say this is how you read an xml file and this is how you read a schema but I'm not seeing some of the
details.

Thanks alot!!!
James


Nov 16 '05 #2
Thank's this was alot of help, I've answered inline.

"Baavgai" <br*****@gmail.com> wrote in message
news:10**********************@k26g2000oda.googlegr oups.com...
While this does lend itself to a relational database model, it's also a
perfectly acceptable XML design.

I was debating storing this data in the database with like a StoreMaster
table and a StoreBooks table but I want(ed) to learn about storing it in XML
files and reading them in to datasets and what role the XSD plays in all of
this.

Let's say there are 1000 stores with various amounts of books. I wouldn't
store this in one big file but rather several small files. I may still go
back to the database but I'm learning alot about XML and XSD right now.
For a Microsoft DataSet, I'd actually opt for version one. It will be
easier to manipulate in code. If you plan on having more than one
store, I'd try something like this:

<Stores>
<Store Name="My Book Store">
<Phone>555-555-5555</Phone>
<Book book_id="1"><Title>Thermodynamics
Unleashed</Title><Price>56.00</Price></Book>
<Book book_id="2"><Title>CAD
CAM</Title><Price>72.00</Price></Book>
<Book book_id="3"><Title>Machine
Design</Title><Price>56.00</Price></Book>
</Store>
</Stores>

If there's really only one store, this might work better for you:
<Store>
<StoreInfo>
<Name>My Book Store</Name>
<Phone>555-555-5555</Phone>
</StoreInfo>
<Book book_id="1"><Title>Thermodynamics
Unleashed</Title><Price>56.00</Price></Book>
<Book book_id="2"><Title>CAD CAM</Title><Price>72.00</Price></Book>
<Book book_id="3"><Title>Machine
Design</Title><Price>56.00</Price></Book>
</Store>

Once you have your design the way you like it, use xsd.exe to make an
instant xsd from it, e.g.
xsd store.xml ( produces store.xsd, all read to go in a VS.NET project
) More info here:
http://msdn.microsoft.com/library/de...ToolXsdexe.asp
Fire up VS.NET ( which I'm hoping you have, else run and get C#
Express, it's a good IDE and free while in beta ). In your project,
include your .xsd. In the visual thing, tell it book_id is the primary
key of book. Of you don't have this toy, the following in the DataSet
element of source will do the same: <xs:unique name="BookKey1"
msdata:PrimaryKey="true"><xs:selector xpath=".//Book" /><xs:field
xpath="@book_id" /></xs:unique>

Now, when you play with your typed DataSet, you should be able to do
something like dataSet.Book.FindBybook_id(2) to grab specific book.

Hope this helps,
Brett
Yes I have VS.net. Thanks it was a help, the big picture is becoming clearer
now


James wrote:
Hi I'm James Newbie

I'm going to use some xml from a previous posters because it's

similiar to
mine

<Store>
<Name> My Book Store</Name>
<Phone> 555-555-5555 </Phone>
<Book id="1" >
<Title>Thermodynamics Unleashed</Title>
<Price>56.00</Price>
</Book>
<Book id="2" >
<Title>CAD CAM</Title>
<Price>72.00</Price>
</Book>
<Book id="3" >
<Title>Machine Design</Title>
<Price>56.00</Price>
</Book>
</Store>
I was thinking of this instead

<Store>
<Name> My Book Store</Name>
<Phone> 555-555-5555 </Phone>
<Books>
<Book id="1" >
<Title>Thermodynamics Unleashed</Title>
<Price>56.00</Price>
</Book>
<Book id="2" >
<Title>CAD CAM</Title>
<Price>72.00</Price>
</Book>
<Book id="3" >
<Title>Machine Design</Title>
<Price>56.00</Price>
</Book>
</Books>
</Store>

Actually I was also thinking of this and the only advantage I can see

(which
may not be one) is that when reading from an XMLDocument I can grab

the
entire Books node and do what I need to.

I'm starting to read about reading XML into a dataset using a schema

and I'm
not sure how this example can work. When I think about a dataset I'm
thinking a big square shaped structure with rows and columns. Now the

above
xml is not square so first that confuses me and I think this is where

the
schema comes into play.

Does the schema assist the data set and say for example put the Name

and
Phone over here and then take all the books and keep them in a table?

If
that is true would I be able to have a form that has two edit boxes,

one for
Name and the other for Phone then a separate datagrid which would

list all
the books?

Any answers, thoughts, examples or otherwise are highly

appreciated!!! I'm
reading about all of this and the examples say this is how you read

an xml
file and this is how you read a schema but I'm not seeing some of the
details.

Thanks alot!!!
James

Nov 16 '05 #3
Hi James,

If you have ever worked with one to many database tables, you will see that
you have a one to many reference to the store (1) to books(3).

In a referential database the schema would look like this:

ONE

TABLE:Store
Fields: Name, Phone

TO Many

TABLE: Books
ID
Title
Price

If were to "flatten" the table out from the scheama, you would see something
like this:

Name Phone ID Title
Price
My Book Store 555-555-5555 1 Thermodynamics Unleashed
56.00
My Book Store 555-555-5555 2 CAD CAM
72.00
My Book Store 555-555-5555 3 Machine Design
56.00

There's your box.

Cheers!

Rob Lykens

"James" wrote:
Hi I'm James Newbie

I'm going to use some xml from a previous posters because it's similiar to
mine

<Store>
<Name> My Book Store</Name>
<Phone> 555-555-5555 </Phone>
<Book id="1" >
<Title>Thermodynamics Unleashed</Title>
<Price>56.00</Price>
</Book>
<Book id="2" >
<Title>CAD CAM</Title>
<Price>72.00</Price>
</Book>
<Book id="3" >
<Title>Machine Design</Title>
<Price>56.00</Price>
</Book>
</Store>
I was thinking of this instead

<Store>
<Name> My Book Store</Name>
<Phone> 555-555-5555 </Phone>
<Books>
<Book id="1" >
<Title>Thermodynamics Unleashed</Title>
<Price>56.00</Price>
</Book>
<Book id="2" >
<Title>CAD CAM</Title>
<Price>72.00</Price>
</Book>
<Book id="3" >
<Title>Machine Design</Title>
<Price>56.00</Price>
</Book>
</Books>
</Store>

Actually I was also thinking of this and the only advantage I can see (which
may not be one) is that when reading from an XMLDocument I can grab the
entire Books node and do what I need to.

I'm starting to read about reading XML into a dataset using a schema and I'm
not sure how this example can work. When I think about a dataset I'm
thinking a big square shaped structure with rows and columns. Now the above
xml is not square so first that confuses me and I think this is where the
schema comes into play.

Does the schema assist the data set and say for example put the Name and
Phone over here and then take all the books and keep them in a table? If
that is true would I be able to have a form that has two edit boxes, one for
Name and the other for Phone then a separate datagrid which would list all
the books?

Any answers, thoughts, examples or otherwise are highly appreciated!!! I'm
reading about all of this and the examples say this is how you read an xml
file and this is how you read a schema but I'm not seeing some of the
details.

Thanks alot!!!
James


Nov 16 '05 #4

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

Similar topics

0
952
by: James | last post by:
Hi I'm James Newbie I'm going to use some xml from a previous posters because it's similiar to mine <Store> <Name> My Book Store</Name> <Phone> 555-555-5555 </Phone> <Book id="1" >...
1
1158
by: Jim | last post by:
I have a class that inherits from the DataGrid class. I want to know when the datasource of my datagrid has changed, but want to execute a function within my extended datagrid class. For...
1
1185
by: Cylix | last post by:
I am going to show database table to a datagrid. I try to select the table to a sqlDataReader, but I found it is not straight to show it to the datagrid. It needs to convert the sqldatareader to a...
2
3875
by: Albin | last post by:
Hi, I have a html page where in the table spans for two pages the first page's last row doesn end properly and the 2nd page's first row also isnt proper.The code i use is given below,the no of...
0
7100
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,...
0
7126
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,...
0
7175
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...
0
7330
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...
1
4865
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...
0
4559
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...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
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...

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.