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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T04:36:12+00:00 2026-05-20T04:36:12+00:00

I have the following code to get some data about companies: XDocument doc =

  • 0

I have the following code to get some data about companies:

XDocument doc = XDocument.Load(new StringReader(searchPayload));
XNamespace ns = ConfigurationManager.AppSettings["WebServiceNamespace"];

var businesses = (from node in doc.Descendants(ns + "searchResultsRecord")
                  let ABN = node.Element(ns + "ABN")
                  let mainName = node.Element(ns + "mainName")
                  let legalName = node.Element(ns + "legalName")
                  let mainTradingName = node.Element(ns + "mainTradingName")
                  let otherTradingName = node.Element(ns + "otherTradingName")
                  let mainBusinessPhysicalAddress = node.Element(ns + "mainBusinessPhysicalAddress")
                  select new
                  {
                      Name = new
                      { 
                          organisationName = (string)mainTradingName.Element(ns + "organisationName"),
                          score = (string)mainTradingName.Element(ns + "score"),
                          isCurrentIndicator = (string)mainTradingName.Element(ns + "isCurrentIndicator"),
                      },
                      ABN = new
                      {
                          identifierValue = (string)ABN.Element(ns + "identifierValue"),
                          identifierStatus = (string)ABN.Element(ns + "identifierStatus"),
                      },
                      Location = new
                      {
                          stateCode = (string)mainBusinessPhysicalAddress.Element(ns + "stateCode"),
                          postCode = (string)mainBusinessPhysicalAddress.Element(ns + "postcode"),
                          isCurrentIndicator = (string)mainBusinessPhysicalAddress.Element(ns + "isCurrentIndicator"),
                      }
                  }).ToList();

searchPayload is a SOAP message returned from a web service and it returnes up to 200 searchResultRecords of which some of them have a mainName node, some legalNode, some all of the nodes and so on. If I use the code above I get the error in the topic because obviously not all result records have all nodes so how can I handle this?

In Name = new I want to get available “name” nodes

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-20T04:36:13+00:00Added an answer on May 20, 2026 at 4:36 am

    I can’t see anything in the lets that would through, since node should always be non-null. And outside the lets the only time you use it is in blah.Element(..) – so you have two choices:

    • filter out the ones that won’t work (will remove data):

      ....
      let mainTradingName = node.Element(ns + "mainTradingName")
      where mainTradingName != null
      ....
      
    • check before using .Element (will default some fields to blank):

      ...
      organisationName = mainTradingName == null ? "" :
            (string)mainTradingName.Element(ns + "organisationName"),
      ...
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code making a GET request on a URL: $('#searchButton').click(function() {
I have the following code, for which I get the error: Warning : mysqli_stmt::bind_result()
I have the following code, I'm trying to get a table with 4 columns
If I have the following Linq code: context.Table1s.InsertOnSubmit(t); context.Table1s.InsertOnSubmit(t2); context.Table1s.InsertOnSubmit(t3); context.SubmitChanges(); And I get
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
currently i have jdbc code with the following basic stucture: get Connection (do the
I have the following Code to display Data from the Database in XML Document
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I'm trying to use opengl in C#. I have following code which fails with

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.