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

  • Thread starter Thread starter Dan
  • Start date Start date
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
 
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
 
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
 
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,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

My vacation and childhood cancer awareness site:
http://www.crazycancertour.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top