Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1022405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:27:37+00:00 2026-05-16T11:27:37+00:00

this is xml let say: <.Sections> <.SECTION ID =4 NAME=GetStudents CONTROL-TYPE=Button LINK=WebForm2.aspx> </SECTION> <.SECTION

  • 0

this is xml let say:

<.Sections>
<.SECTION ID ="4" NAME="GetStudents" CONTROL-TYPE="Button" LINK="WebForm2.aspx">

      </SECTION>
      <.SECTION ID="5" NAME="SelectStudent" CONTROL-TYPE="Drowpdown" METHOD ="selectList_MethodName">

      </SECTION>

Observe this xml, I am generating the UI controls base on “CONTROL-TYPE” Attributes. but there are different attributes are there in both sections elements. as LINK and METHOD . I want to query like this , if section’s CONTROL-TYPE==”Button” then get value of LINK attribute Else If CONTROL-TYPE==”Drowpdown” then get value of METHOD attribute Else If.

I am trying to write code in c# +ASP.net. how to achieve this? is there way get such data ?

NOTE: please don’t go on dot inside tag as <.SECTION>. it is for this forum page understanding.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:27:38+00:00Added an answer on May 16, 2026 at 11:27 am

    Well, the simplest way is either an explicit if/else:

    string value;
    string controlType = (string) element.Attribute("CONTROL-TYPE");
    if (controlType == "Button")
    {
        value = (string) element.Attribute("LINK");
    }
    else if (controlType == "Dropdown")
    {
        value = (string) element.Attribute("METHOD");
    }
    else
    {
        // What do you want to happen if it's neither of these?
    }
    

    … or use the conditional operator if you’re happy with a simple default value for other control types:

    string controlType = (string) element.Attribute("CONTROL-TYPE");
    string value = controlType == "Button" ? (string) element.Attribute("LINK")
                 : controlType == "Dropdown" ? (string) element.Attribute("METHOD")
                 : "default value";
    

    EDIT: Within a query expression, there are two reasonable ways to do this. First, you could use the conditional operator and a let clause to fetch the control type just once:

    var query = 
         from element in elements
         let controlType = (string) element.Attribute("CONTROL-TYPE")
         select new {
             ID = (string) element.Attribute("ID"),
             XYZ = controlType == "Button" ? (string) element.Attribute("LINK")
                 : controlType == "Dropdown" ? (string) element.Attribute("METHOD")
                : "default value"
         };
    

    Alternatively – and preferrably, IMO – put this logic into a method, and then call the method from the select clause:

    var query = 
         from element in elements
         let controlType = (string) element.Attribute("CONTROL-TYPE")
         select new {
             ID = (string) element.Attribute("ID"),
             XYZ = GetXyz(element);
         };
    
    ...
    private static void GetXyz(XElement element)
    {
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say that I've got this xml: <items> <item name=thumb> <downloadStream>test1</downloadStream> <downloadStream>test2</downloadStream> <downloadStream>test3</downloadStream> </item>
Let's say that I have something like this in my web.xml file. <filter name=foo>
Let's say I have this XML file: <Names> <Name> <FirstName>John</FirstName> <LastName>Smith</LastName> </Name> <Name> <FirstName>James</FirstName>
Let's say I have an xml file with this part: <tag name=key value=${tag.val}/> This
Let's say I have an XML file such as this: <root> <level1 name=level1A> <level2
Given this XML: <?xml version=1.0 encoding=utf-8?> <content dataType=XML> <item type=Promotion name=Sample Promotion expires=04/01/2009> <![CDATA[
Let's say I have a series of xml files in this format: A.xml: <page>
let's say, I have this xml file: <?xml version=1.0 encoding=UTF-8 ?> <TimeSeries> <timeZone>1.0</timeZone> <series>
Let's say you have this xml: <yyy:response xmlns:xxx='http://domain.com'> <yyy:success> <yyy:data>some-value</yyy:data> </yyy:success> </yyy:response> How would
So let's say I've got a simple XML document like this: <a> <b> <c>blah</c>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.