views:

45

answers:

0

I have an XML in this format which is mapped to corresponding Objects in VB.NET.

<Control Name="LoginPage" LabelAlignment="Right" FieldAlignment="Left" DisplayPoweredByLogo="False">
    <Fields>
      <FieldGroup Name="Admin" Visible="True" LayoutPosition="Left">
        <AdminID Visible="False" Required="False" EnableChange="False" MaxLength="20" FieldWidthInPixels="50" LayoutPosition="Left"
                    LabelText="Admin ID:"></AdminID>
        <Zip Visible="True" Required="True" EnableChange="True" MaxLength="5" FieldWidthInPixels="25" LayoutPosition="Left"
                    LabelText="Zip Code:"></Zip>
        <UDK1 Visible="False" Required="False" EnableChange="False" MaxLength="8" FieldWidthInPixels="30" LayoutPosition="Left"
                    LabelText="UDK1:"></UDK1>
        <ReferenceCode Visible="False" Required="False" EnableChange="False" MaxLength="32" FieldWidthInPixels="75" LayoutPosition="Left"
                    LabelText="Reference #:"></ReferenceCode>
      </FieldGroup>
      <FieldGroup Name="User" Visible="False">
        <UserID Visible="True" Required="True" EnableChange="True" MaxLength="64" FieldWidthInPixels="100" LayoutPosition="Left"
                LabelText="User ID:"></UserID>
        <Password Visible="True" Required="True" EnableChange="True" MaxLength="32" FieldWidthInPixels="100" LayoutPosition="Left"
                LabelText="Password:"></Password>
      </FieldGroup>
    </Fields>
    <Buttons Visible="True" Alignment="Center" ButtonType="Image">
      <Cancel Visible="True" LabelText="Cancel"></Cancel>
      <Reset Visible="False"/>
      <Submit Visible="True" LabelText="Login"></Submit>
    </Buttons>
    <ValidationMessages>
      <CustomerIDRequired>Please enter your Account Number.</CustomerIDRequired>
      <UserIDRequired>Please enter your Email Address to Login.</UserIDRequired>
      <PasswordRequired>Please enter your Password.</PasswordRequired>
      <CredentialsError>Invalid credentials. Your UserName/Password is incorrect.</CredentialsError>
    </ValidationMessages>
  </Control>

Basically, each <Control> element in this xml can have one or more fields with the fieldname as the node or they could be grouped as <FieldGroups> and it may have <Buttons> and/or <ValidationMessage> nodes.

This structure is represented in objects as well with Control object that has individual properties for the attributes like Name, Layout etc and has a Queue Property to include the Fields & FieldGroups, Buttons in the order they are defined in the XML to render First in First out. There are other classes for FieldGroup and Field that includes the properties of each field and field group etc. Which needs to be created as we go and added to the Queue.

The condition here is that only all Fields, FieldGroups, Buttons with attribute Visible="True" needs to be in the Queue.

I am fairly new to Linq and wondering how can I write a single Linq query with case statements to create the control object and fill in the Queue property of this class with all visible child node elements mapped to its respective objects.

Is there any help on creating nested controls or arrays on the fly without writing a separate iterator to load these items in the queue?