469,268 Members | 1,002 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

DataGrid support for XML with different node types

Hello,

I have xml like this....

<test>
<question>sdfsa</question>
<section><question>43ga</question>
<question>asdf</question>
</test>

I make and xsd file with
<xs:all>
<xs:element....
<xs:element....
</xs:all>

I then bind the XML to a DataGrid...

DataGrid.DataSource = DataSet;
DataGrid.DataBind();

but I only get the questions, I notice there is a DataMember property
I can set to DataGrid.DataMember = "Section"; and I will get that one,
but essential I want a table with both elements in there...

Is there anyway to do this...?

Thank You
Nov 12 '05 #1
2 3093
Hi Magister

Try creating a DataSet in Visual Studio .NET using the design time
environment - you will see that if you create an element, then add a couple
of 'fields' to it, then the structure you get in the xsd looks a bit like
this:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Test" targetNamespace="http://tempuri.org/Test.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="http://tempuri.org/Test.xsd"
xmlns:mstns="http://tempuri.org/Test.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Test" msdata:IsDataSet="true">
<xs:complexType>
<xs:all>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element name="Question" type="xs:string" minOccurs="0" />
<xs:element name="Answer" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>

Then you can bind to the Question and Answer 'columns' by setting the
DataSource. Essentially the XML data needs to look more table like to work
the way that you want, with a root element representing the table, top level
element children of the root representing rows, and grand children of the
root representing columns.

HTH

Nigel

"magister" wrote:
Hello,

I have xml like this....

<test>
<question>sdfsa</question>
<section><question>43ga</question>
<question>asdf</question>
</test>

I make and xsd file with
<xs:all>
<xs:element....
<xs:element....
</xs:all>

I then bind the XML to a DataGrid...

DataGrid.DataSource = DataSet;
DataGrid.DataBind();

but I only get the questions, I notice there is a DataMember property
I can set to DataGrid.DataMember = "Section"; and I will get that one,
but essential I want a table with both elements in there...

Is there anyway to do this...?

Thank You

Nov 12 '05 #2
Thanks for getting back to me, the thing is that I am binding to a
hierarchical grid control....I am using attributes as columns...

<test>
<question Type="Selection" Text="What is the capital of the USA">
<option Text="Texas" />
<option Text="DC" />
</question>
<section Type="Random" Text="Here is a section about France" >
<question Type="Selection" Text="What is the capital of the
France">
<option Text="Paris" />
<option Text="Lyon" />
</question>
<question Type="Input" Text="Type in the major language spoken in
France">
</section>
<question Type="Input" Text="Type in the major language spoken in
the USA">
<question Type="Selection" Text="What is the capital of the UK">>
<option Text="London" />
<option Text="Manchester" />
</question>
</test>

I wanteded to bind the columns of question and section in the first
level of the hierarchical grid as they have similar attribute columns,
but when I get my typed Dataset Section and Question are 2 different
tables...how can I put them together so they are one...?

Thanks,
Matt

Nigel Armstrong <Nigel Ar*******@discussions.microsoft.com> wrote in message news:<70**********************************@microso ft.com>...
Hi Magister

Try creating a DataSet in Visual Studio .NET using the design time
environment - you will see that if you create an element, then add a couple
of 'fields' to it, then the structure you get in the xsd looks a bit like
this:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Test" targetNamespace="http://tempuri.org/Test.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified" xmlns="http://tempuri.org/Test.xsd"
xmlns:mstns="http://tempuri.org/Test.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Test" msdata:IsDataSet="true">
<xs:complexType>
<xs:all>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element name="Question" type="xs:string" minOccurs="0" />
<xs:element name="Answer" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>

Then you can bind to the Question and Answer 'columns' by setting the
DataSource. Essentially the XML data needs to look more table like to work
the way that you want, with a root element representing the table, top level
element children of the root representing rows, and grand children of the
root representing columns.

HTH

Nigel

"magister" wrote:
Hello,

I have xml like this....

<test>
<question>sdfsa</question>
<section><question>43ga</question>
<question>asdf</question>
</test>

I make and xsd file with
<xs:all>
<xs:element....
<xs:element....
</xs:all>

I then bind the XML to a DataGrid...

DataGrid.DataSource = DataSet;
DataGrid.DataBind();

but I only get the questions, I notice there is a DataMember property
I can set to DataGrid.DataMember = "Section"; and I will get that one,
but essential I want a table with both elements in there...

Is there anyway to do this...?

Thank You

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Emerson | last post: by
1 post views Thread by Torre Quinn | last post: by
1 post views Thread by Michael Gorbach | last post: by
3 posts views Thread by Raghuvansh | last post: by
4 posts views Thread by Mark Waser | last post: by
5 posts views Thread by lanem | last post: by
3 posts views Thread by Rodi Roberto | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.