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 6878639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:44:56+00:00 2026-05-27T04:44:56+00:00

I am using the code below string xml = @<?xml version=’1.0′ encoding=’UTF-8′?> <widgets> <widget>

  • 0

I am using the code below

string xml = @"<?xml version='1.0' encoding='UTF-8'?>
<widgets>
    <widget>
        <url>~/Portal/Widgets/ServicesList.ascx</url>
        <castAs>ServicesWidget</castAs>
        <urlType>ascx</urlType>
        <parameters>
            <PortalCategoryId>3</PortalCategoryId>
        </parameters>
    </widget>
    <widget>
        <url>www.omegacoder.com</url>
        <castAs>ServicesWidget</castAs>
        <urlType>htm</urlType>
        <parameters>
            <PortalCategoryId>41</PortalCategoryId>
        </parameters>
    </widget>
</widgets>";

XDocument loaded = XDocument.Parse( xml );

var widgets = from x in loaded.Descendants( "widget" )
              select new
              {
                  URL = x.Descendants( "url" ).First().Value,
                  Category = x.Descendants( "PortalCategoryId" ).First().Value
              };

foreach ( var wd in widgets )
    Console.WriteLine( "Widget at ({0}) has a category of {1}", wd.URL, wd.Category );

This gives me the URL and Category for the first widget only? Not sure how can I get the values for second one.
Also how can I get the index of the widget like 0 and 1 and so on….depending on how many widgets are there.

thanks

  • 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-27T04:44:56+00:00Added an answer on May 27, 2026 at 4:44 am

    Your query return entries for both widgets for me, I’ve tried your code without any changes.

    Following query will help you get index for each widget as well:

    var widgets = loaded.Descendants("widget").Select((w, i) =>
                       new
                       {        
                         WidgetIndex = i,
                         URL = w.Descendants( "url" )
                                .FirstOrDefault()
                                .Value,
                         Category = w.Descendants("PortalCategoryId")
                                     .FirstOrDefault()
                                     .Value
                       });
    

    String representation:

    string widgetsInfo = 
        loaded.Descendants("widget")
              .Select((w, i) =>
                    new
                        {
                            WidgetIndex = i,
                            URL = w.Descendants("url").FirstOrDefault().Value,
                            Category = w.Descendants("PortalCategoryId").FirstOrDefault().Value
                        })
                .Select(w => String.Format("Index:{0}; URL:{1}; CATEGORY:{2}; ",
                                            w.WidgetIndex, w.URL, w.Category))
                .Aggregate((acc, next) => acc + Environment.NewLine + next);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have below string in javascript var output = '<?xml version=1.0 encoding=UTF-8 standalone=yes?><abc><xyz><xyzResponse><URL>http%3A%2F%2Flocalhost%3A8080%2Fnet%2Fxyz.do%3Fpartner%3Ddummy%26id%3Dba0e245f-ae67-40b6-986d-3242acea4c04</URL><StatusMsg>SUCCESS</StatusMsg><ID>hello.com</ID><AID>test</AID></xyzResponse></xyz></abc>'; I
Below is the XML schema I am trying to conform to: <?xml version=1.0 encoding=UTF-8?>
I have the code below: string SQL = select * from + TableName; using
I have the following XML: <?xml version=1.0 encoding=UTF-8?> <gnm:Workbook xmlns:gnm=http://www.gnumeric.org/v10.dtd xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.gnumeric.org/v9.xsd> <office:document-meta xmlns:office=urn:oasis:names:tc:opendocument:xmlns:office:1.0
I'm trying to send a string via ftp using the code below but I'm
Given the following XML: <?xml version=1.0 encoding=UTF-8?> <userAttributeList> <attribute> <userId>12345678</userId> <attId>1234</attId> <attName>Group</attName> <attTypeId>8</attTypeId> <attTypeName>User
I am trying to pass the XML code below, in the first instance using
Using the code below, I am returning an nvarchar field from MS SQL 2005
Using the code below, I am attempting to fill a Canvas with UIElements and
Using the code below (from a console app I've cobbled together), I add seven

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.