Can I create DataSet in the designer and use it to parse xml file?

D

Dan

Hi,

Can I use the designer to create a typed DataSet and then use it to parse
xml file?

If yes, could someone please describe the necessary steps or point me to
on-line docs?

For example, how would I define a DataSet in the designer for the following
xml:
[...]
<parent>
<parent_id>1</parent_id>
<name>parent1</name>
<child>
<child_id>1</child_id>
<name>child1</name>
</child>
<child>
<child_id>2</child_id>
<name>child2</name>
</child>
</parent>
<parent>
[...]
</parent>

I'd appreciate _any_ suggestions.
Thanks,
Dan
 
S

Scott M.

Sorry, didn't read that carefully enough.

The designer isn't going to be useful to create actual XML that has data in
it. The designer is for creating a schema that some XML must adhere to for
it to be considered valid.

-Scott

Scott M. said:
DataSet.ReadXml


Dan said:
Hi,

Can I use the designer to create a typed DataSet and then use it to parse
xml file?

If yes, could someone please describe the necessary steps or point me to
on-line docs?

For example, how would I define a DataSet in the designer for the
following xml:
[...]
<parent>
<parent_id>1</parent_id>
<name>parent1</name>
<child>
<child_id>1</child_id>
<name>child1</name>
</child>
<child>
<child_id>2</child_id>
<name>child2</name>
</child>
</parent>
<parent>
[...]
</parent>

I'd appreciate _any_ suggestions.
Thanks,
Dan
 
D

Dan

Scott,

Thanks for a quick reply. My original post was probably not that clear
because "...The designer is for creating a schema that some XML must adhere
to for it to be considered valid..." is exactly what I'd like to do :).

Given the example in my original post, how do I create a corresponding
DataSet in the designer?

I'm guessing that I'd need to do the following:

In the designer:
1) create an empty dataset
2) add 2 tables: parent and child
3) define columns for the above tables
4) Q: how do I define relations between parent and child tables? What key
do I use?

In code:
1) instantiate DataSet object based on the class auto-generated above
2) call ReadXml()

Is the above approach somewhat correct?

Again, any help will be greatly appreciated.

Dan



Scott M. said:
Sorry, didn't read that carefully enough.

The designer isn't going to be useful to create actual XML that has data
in it. The designer is for creating a schema that some XML must adhere to
for it to be considered valid.

-Scott

Scott M. said:
DataSet.ReadXml


Dan said:
Hi,

Can I use the designer to create a typed DataSet and then use it to
parse xml file?

If yes, could someone please describe the necessary steps or point me to
on-line docs?

For example, how would I define a DataSet in the designer for the
following xml:
[...]
<parent>
<parent_id>1</parent_id>
<name>parent1</name>
<child>
<child_id>1</child_id>
<name>child1</name>
</child>
<child>
<child_id>2</child_id>
<name>child2</name>
</child>
</parent>
<parent>
[...]
</parent>

I'd appreciate _any_ suggestions.
Thanks,
Dan
 
G

Gregory A. Beamer

Hi,

Can I use the designer to create a typed DataSet and then use it to
parse xml file?

If yes, could someone please describe the necessary steps or point me
to on-line docs?

For example, how would I define a DataSet in the designer for the
following xml:
[...]
<parent>
<parent_id>1</parent_id>
<name>parent1</name>
<child>
<child_id>1</child_id>
<name>child1</name>
</child>
<child>
<child_id>2</child_id>
<name>child2</name>
</child>
</parent>
<parent>
[...]
</parent>

I'd appreciate _any_ suggestions.

Yes and no.

Earlier versions of Visual Studio had better features for creating an
XML Schema and not merely a DataSet. If you are aiming for XML schema,
you might find your designed schema is not accurate. If, however, a
DataSet is what you are testing against, then you should be fun. That is
the designer gotcha.

As for validation, Scott's suggestion will work, since your XSD is a
DataSet. If it fails to load, it is not valid.

But, that is not the answer you want. You can also use a validating
reader and add the schema in question to the reader. This will validate
the XML to schema, while giving you some clue of why the XML is not
valid (loading a DataSet merely gives an exception).

Peace and Grace,
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top