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

J

James

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
 
G

Guest

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
 
B

Baavgai

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/d...s/html/cpconXMLSchemaDefinitionToolXsdexe.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
 
J

James

Thank's this was alot of help, I've answered inline.

Baavgai said:
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/d...s/html/cpconXMLSchemaDefinitionToolXsdexe.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top