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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:17:57+00:00 2026-05-18T11:17:57+00:00

What I have is an XML we receive from a web service which represents

  • 0

What I have is an XML we receive from a web service which represents a list of questions. The questions are broken down by type which indicates how they should be displayed on the web. For instance:

<step id="109025">
  <stepinf enabled="Yes" errors="0" id="First Name" mandatory="Yes" name="sti_115511" type="FIL">
    <field_label>First Name</field_label>
    <screen_value></screen_value>
  </stepinf>
  <stepinf enabled="Yes" errors="0" id="Last Name" mandatory="Yes" name="sti_115513" type="FIL">
    <field_label>Last Name</field_label>
    <screen_value></screen_value>
  </stepinf>
  <stepinf enabled="Yes" errors="0" id="State" mandatory="Yes" name="sti_109257" type="STE">
    <field_label>State</field_label>
    <screen_value></screen_value>
    <options_list>
      <option label="AK">AK - Alaska</option>
      <option label="AL">AL - Alabama</option>
      <option label="AR">AR - Arkansas</option>
      <option label="AS">AS - American Samoa (Terr.)</option>
      <option label="AZ">AZ - Arizona</option>
      ...
    </options_list>
  </stepinf>
</step>

The type “STE” indicates that it will display on the web as a select box.

I am populating a List<> of a custom type I created by doing the following:

var stepinfList = (from stepinf in xdoc.Descendants("stepinf")
    select new Question
    {
       TextID = stepinf.Attribute("id").Value,
       Type = stepinf.Attribute("type").Value,
       Name = stepinf.Attribute("name").Value,
       Label = stepinf.Element("field_label").Value,
       Required = stepinf.Attribute("mandatory").Value,
       ErrorCount = int.Parse(stepinf.Attribute("errors").Value)
    }).ToList();

Where I am getting lost at is I have no idea how to get the option sub-elements into my results. I tried creating a property in the Question type named Options which I defined as an IDictionary and then utilized a sub-select in my LINQ query and the ToDictionary extension.

Options = (from option in xdoc.Element("options_list").Elements("option")
    select option)
    .ToDictionary(x => x.Attribute("label").Value, x => x.Value)

This didn’t work as I think it bombs on the stepinf records that do not have child option_list elements. Anyway, I get “Object reference not set to an instance of an object” on the LINQ statement when I run the page.

I’m afraid this is above my current LINQ skill set so any help would be greatly appreciated.

  • 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-18T11:17:57+00:00Added an answer on May 18, 2026 at 11:17 am

    This didn’t work as I think it bombs
    on the stepinf records that do not
    have child option_list elements.

    Your assessment is correct, so you need to check whether option_list exists before querying it. Check if it’s null and return the dictionary or return null accordingly.

    Try this:

    Options = stepinf.Element("options_list") == null ? null :
                  stepinf.Element("options_list").Elements("option")
                         .ToDictionary(x => x.Attribute("label").Value, x => x.Value)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
I have a web application which receives about 50 hits per second, and on
I have the following Soap Request I receive from the client, where basically I
I have xml where some of the element values are unicode characters. Is it
I have xml files I want to read in and store in the database.
I have XML files in a directory that I wish to get over to
I have XML with a value like the following: <products> <product id=1 name=All Products>
Is it possible to have XML-embedded JavaScript executed to assist in client-side (browser-based) XSL
Greetings! If I have XML such as this: <Root> <AlphaSection> . . . </AlphaSection>
My question is the following. I have xml that is versioned by a namespace.

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.