Linq to XML Read and output XML generated from lookup list

Posted by Greg S on Stack Overflow See other posts from Stack Overflow or by Greg S
Published on 2010-04-27T21:10:00Z Indexed on 2010/05/27 3:51 UTC
Read the original article Hit count: 448

Filed under:
|
|
|

I am trying to use XML created from a lookup list in SharePoint as a datasource for a treeview. It is in the form of :

<NewDataSet>
  <test_data>
    <ID>1</ID>
    <Title>MenuItem_1</Title>
    <child_of />    
  </test_data>
  <test_data>
    <ID>2</ID>
    <Title>Subitem_1</Title>
    <Action>http://www.google.com</Action>
    <child_of>MenuItem_1</child_of>   
  </test_data>
  <test_data>
    <ID>3</ID>
    <Title>Subitem_2</Title>
    <Action>http://www.google.com</Action>
    <child_of>MenuItem_1</child_of>
  </test_data>
  <test_data>
    <ID>4</ID>
    <Title>MenuItem_2</Title>
    <child_of />
  </test_data>
  <test_data>
    <ID>5</ID>
    <Title>Subitem_2_1</Title>
    <Action>http://www.google.com</Action>
    <child_of>MenuItem_2</child_of>
  </test_data>
  <test_data>
    <ID>6</ID>
    <Title>Subitem_2_2</Title>
    <Action>http://www.google.com</Action>
    <child_of>MenuItem_2</child_of>
  </test_data>
  <test_data>
    <ID>7</ID>
    <Title>Subitem_2_2_1</Title>
    <Action>http://www.google.com</Action>
    <child_of>Subitem_2_2</child_of>
  </test_data>
</NewDataSet>

There may be N tiers, but the items relate to the parent via the <child_of> element. I can't seem to figure out how to write the LINQ in C# to nest the menu items properly. A friend recommended I post here. Any help is greatly appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about Silverlight