Pull nested xml values into Datagrid
-
Im looking to display xml values via a datagrid. And so far Ive had luck with everything, except nested values.
<?xml version="1.0" encoding="UTF-8"?>
<Collection>
<Content>
<ID>16938</ID>
<Type>Content</Type>
<Title>Smartform2</Title>
<QuickLink>/it.aspx?id=16938</QuickLink>
<Teaser>
<p>SmartForm1Smartform2Smartform3Smartform4</p>
</Teaser>
<Html>
<root>
<Field1>
<Field2>
<Test1>SmartForm1</Test1>
<Test2>Smartform2</Test2>
</Field2>
<Field2>
<Test1>Smartform3</Test1>
<Test2>Smartform4</Test2>
</Field2>
</Field1>
</root>
</Html>
<StartDate>1/1/0001 12:00:00 AM</StartDate>
<DateModified>5/28/2009 3:02:59 PM</DateModified>
<DateCreated>5/28/2009 3:02:49 PM</DateCreated>
<EndDate>12/31/9999 11:59:59 PM</EndDate>
<LastEditorFname>Erik</LastEditorFname>
<LastEditorLname>Kozlowski</LastEditorLname>
<Hyperlink>
<a href="/it.aspx?id=16938">Smartform2</a>
</Hyperlink>
<DisplayStartDate/>
<FolderID>2594</FolderID>
<ContentStatus>A</ContentStatus>
<Language>1033</Language>
<DisplayDateModified>5/28/2009</DisplayDateModified>
<DisplayDateCreated>5/28/2009</DisplayDateCreated>
<DisplayEndDate/>
<EndDateAction>Archive_Expire</EndDateAction>
<Comment/>
<Image>/WorkArea/images/application/spacer.gif</Image>
<ImageThumbnail>/WorkArea/images/application/thumb_spacer.png</ImageThumbnail>
<FilePath>/it.aspx?id=16938</FilePath>
</Content>
<Content>
<ID>16936</ID>
<Type>Content</Type>
<Title>Test smartform 1</Title>
<QuickLink>/it.aspx?id=16936</QuickLink>
<Teaser>
<p>Smart1Smart2Smart3Smart4</p>
</Teaser>
<Html>
<root>
<Field1>
<Field2>
<Test1>Smart1</Test1>
<Test2>Smart2</Test2>
</Field2>
<Field2>
<Test1>Smart3</Test1>
<Test2>Smart4</Test2>
</Field2>
</Field1>
</root>
& -
Im looking to display xml values via a datagrid. And so far Ive had luck with everything, except nested values.
<?xml version="1.0" encoding="UTF-8"?>
<Collection>
<Content>
<ID>16938</ID>
<Type>Content</Type>
<Title>Smartform2</Title>
<QuickLink>/it.aspx?id=16938</QuickLink>
<Teaser>
<p>SmartForm1Smartform2Smartform3Smartform4</p>
</Teaser>
<Html>
<root>
<Field1>
<Field2>
<Test1>SmartForm1</Test1>
<Test2>Smartform2</Test2>
</Field2>
<Field2>
<Test1>Smartform3</Test1>
<Test2>Smartform4</Test2>
</Field2>
</Field1>
</root>
</Html>
<StartDate>1/1/0001 12:00:00 AM</StartDate>
<DateModified>5/28/2009 3:02:59 PM</DateModified>
<DateCreated>5/28/2009 3:02:49 PM</DateCreated>
<EndDate>12/31/9999 11:59:59 PM</EndDate>
<LastEditorFname>Erik</LastEditorFname>
<LastEditorLname>Kozlowski</LastEditorLname>
<Hyperlink>
<a href="/it.aspx?id=16938">Smartform2</a>
</Hyperlink>
<DisplayStartDate/>
<FolderID>2594</FolderID>
<ContentStatus>A</ContentStatus>
<Language>1033</Language>
<DisplayDateModified>5/28/2009</DisplayDateModified>
<DisplayDateCreated>5/28/2009</DisplayDateCreated>
<DisplayEndDate/>
<EndDateAction>Archive_Expire</EndDateAction>
<Comment/>
<Image>/WorkArea/images/application/spacer.gif</Image>
<ImageThumbnail>/WorkArea/images/application/thumb_spacer.png</ImageThumbnail>
<FilePath>/it.aspx?id=16938</FilePath>
</Content>
<Content>
<ID>16936</ID>
<Type>Content</Type>
<Title>Test smartform 1</Title>
<QuickLink>/it.aspx?id=16936</QuickLink>
<Teaser>
<p>Smart1Smart2Smart3Smart4</p>
</Teaser>
<Html>
<root>
<Field1>
<Field2>
<Test1>Smart1</Test1>
<Test2>Smart2</Test2>
</Field2>
<Field2>
<Test1>Smart3</Test1>
<Test2>Smart4</Test2>
</Field2>
</Field1>
</root>
&I am assuming you are loading the xml to a dataset before binding the grid. Since you have nested xml, they will be loaded as different datatables I think. If this is the case, you can use the merge function to marge the datatables in your dataset and get it to display in your grid. This will be my first try.. There are many other way to do this. It all depends on the complixity of your xml structure
-
Im looking to display xml values via a datagrid. And so far Ive had luck with everything, except nested values.
<?xml version="1.0" encoding="UTF-8"?>
<Collection>
<Content>
<ID>16938</ID>
<Type>Content</Type>
<Title>Smartform2</Title>
<QuickLink>/it.aspx?id=16938</QuickLink>
<Teaser>
<p>SmartForm1Smartform2Smartform3Smartform4</p>
</Teaser>
<Html>
<root>
<Field1>
<Field2>
<Test1>SmartForm1</Test1>
<Test2>Smartform2</Test2>
</Field2>
<Field2>
<Test1>Smartform3</Test1>
<Test2>Smartform4</Test2>
</Field2>
</Field1>
</root>
</Html>
<StartDate>1/1/0001 12:00:00 AM</StartDate>
<DateModified>5/28/2009 3:02:59 PM</DateModified>
<DateCreated>5/28/2009 3:02:49 PM</DateCreated>
<EndDate>12/31/9999 11:59:59 PM</EndDate>
<LastEditorFname>Erik</LastEditorFname>
<LastEditorLname>Kozlowski</LastEditorLname>
<Hyperlink>
<a href="/it.aspx?id=16938">Smartform2</a>
</Hyperlink>
<DisplayStartDate/>
<FolderID>2594</FolderID>
<ContentStatus>A</ContentStatus>
<Language>1033</Language>
<DisplayDateModified>5/28/2009</DisplayDateModified>
<DisplayDateCreated>5/28/2009</DisplayDateCreated>
<DisplayEndDate/>
<EndDateAction>Archive_Expire</EndDateAction>
<Comment/>
<Image>/WorkArea/images/application/spacer.gif</Image>
<ImageThumbnail>/WorkArea/images/application/thumb_spacer.png</ImageThumbnail>
<FilePath>/it.aspx?id=16938</FilePath>
</Content>
<Content>
<ID>16936</ID>
<Type>Content</Type>
<Title>Test smartform 1</Title>
<QuickLink>/it.aspx?id=16936</QuickLink>
<Teaser>
<p>Smart1Smart2Smart3Smart4</p>
</Teaser>
<Html>
<root>
<Field1>
<Field2>
<Test1>Smart1</Test1>
<Test2>Smart2</Test2>
</Field2>
<Field2>
<Test1>Smart3</Test1>
<Test2>Smart4</Test2>
</Field2>
</Field1>
</root>
&After loading an XML file into DataSet; DataSet creates number of DataTable instances so you have to decide which datatable instance you want to use. For Example, DataSet ds=new DataSet(); ds.ReadXml(....); // List of DataTables for(int i=0;iA DATAPOST COMPUTER CENTRE (K.V Prajapati)