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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:56:59+00:00 2026-06-12T08:56:59+00:00

I have xml like this: <soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance> <soapenv:Body> <supplyCrew xmlns=http://site.ddf.com> <login> <login>XXXX</login>

  • 0

I have xml like this:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
  <supplyCrew xmlns="http://site.ddf.com">
     <login>
        <login>XXXX</login>
        <password>XXXX</password>
     </login>
     <flightInformation>
        <flights>
           <item>
              <arrivalDateTime>2010-11-08T22:48:00.000Z</arrivalDateTime>
              <arrivingCity>ORD</arrivingCity>
              <crewMembers>
                 <item>
                    <employeeId>020040</employeeId>
                    <isDepositor>Y</isDepositor>
                    <isTransmitter>N</isTransmitter>
                 </item>
                 <item>
                    <employeeId>09000</employeeId>
                    <isDepositor>N</isDepositor>
                    <isTransmitter>Y</isTransmitter>
                 </item>
              </crewMembers>
           </item>
           <item>
              <arrivalDateTime>2010-11-08T20:29:00.000Z</arrivalDateTime>
              <arrivingCity>JFK</arrivingCity>
              <crewMembers>
                 <item>
                    <employeeId>0538</employeeId>
                    <isDepositor>Y</isDepositor>
                    <isTransmitter>N</isTransmitter>
                 </item>
                 <item>
                    <employeeId>097790</employeeId>
                    <isDepositor>N</isDepositor>
                    <isTransmitter>Y</isTransmitter>
                 </item>
              </crewMembers>
           </item>
        </flights>
     </flightInformation>
  </supplyCrew>

This code gets only the first item ” and ” and then generate a exception ‘System.NullReferenceException’.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Xml;
using System.Data.SqlClient;
using System.Data;
using System.IO;

namespace ConsoleApplication1
{

class Program
{ 

  static void Main(string[] args)
    {


        XElement doc = XElement.Load("U:/Crew.xml");
        XNamespace e = "http://schemas.xmlsoap.org/soap/envelope/";
        XNamespace s = "http://site.ddf.com";

                   var flights = doc.Elements(e + "Body")
        .Elements(s + "supplyCrew")
        .Elements(s + "flightInformation")
        .Elements(s + "flights")
        .Elements(s + "item")
        .Select(
        flight_item => new
        {
            //Anonymous Type
            arrivalDateTime = flight_item.Element(s + "arrivalDateTime").Value,
            arrivingCity = flight_item.Element(s + "arrivingCity").Value,
            crewmember = flight_item.Elements(s + "crewMembers").Elements(s + "item"),

        }
        );


        int index = 1;
        foreach (var flight_item in flights)
        {

            Console.Write('\n'+"New flight item:"+'\n');
            Console.Write('\t'+flight_item.arrivalDateTime + '\n');
            Console.Write('\t'+flight_item.arrivingCity + '\n');

            foreach (var item in flight_item.crewmember)
            {
                var employeeId = item;//crewmember.Elements(s + "item").Elements("employeeId");
                Console.Write("\t  "+employeeId);
                Console.Write('\n');
                //index++;
            }

        }

The idea is to get item.arrivalDateTime and item.arrivingCity and its crewMembers.item.employeeId for all the rows. However I do not know how to get the childnodes using linq…us occrring a exception if when try employeeId = x.Element(s + “employeeId”).Value….

Result should be something like this:

2010-11-08T22:48:00.000Z; ORD; 020040

2010-11-08T22:48:00.000Z; ORD; 09000

2010-11-08T20:29:00.000Z; JFK; 0538

2010-11-08T20:29:00.000Z; JFK; 097790

  • 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-06-12T08:57:00+00:00Added an answer on June 12, 2026 at 8:57 am

    SOLVED

    we just need to replace that foreach for :

            foreach (var flight_item in l_flights)
            {
    
                Console.Write('\n'+"New flight item:"+'\n');
                Console.Write('\t'+flight_item.arrivalDateTime + '\n');
                Console.Write('\t'+flight_item.arrivingCity + '\n');
    
                foreach (var item in flight_item.crewmember)
                {
                    var employeeId = item.Element(s + "employeeId").Value;
                    var isDepositor = item.Element(s + "isDepositor").Value;
                    var isTransmitter = item.Element(s + "isTransmitter").Value;
    
                    Console.Write("\t  " + employeeId + "\n");
                    Console.Write("\t  " + isDepositor + "\n");
                    Console.Write("\t  " + isTransmitter + "\n");
    
                }
    
            }
    

    Thank you guys….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XML Like this: <?xml version=1.0 encoding=utf-8?> <soap:Envelope xmlns:soap=http://www.w3.org/2003/05/soap-envelope xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xmlns:xsd=http://www.w3.org/2001/XMLSchema> <soap:Body>
I need to create SOAP request like this: <soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/ xmlns:stor=http://storage.xdoc.xx/> <soapenv:Header/> <soapenv:Body> <stor:createDocument>
I have a soap request returning a response like below: <SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsd=http://www.w3.org/2001/XMLSchema xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
I have the following XML: <soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/ xmlns:axis=http://ws.apache.org/axis2> <soapenv:Header/> <soapenv:Body> <axis:ErrorQueueInput> <errorStr>JIRA Topic</errorStr> <InputMessage>
I have the following SOAP response: <?xml version=1.0?> <env:Envelope xmlns:env=http://schemas.xmlsoap.org/soap/envelope/> <env:Header/> <env:Body> <GetSalesResponse xmlns=http://api.dgm-uk.com/Publisher/schemas>
<soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/> <soapenv:Body> <tns:send xmlns:tns=http://www.test.com/Service/v3> <NS2:Message release=006 version=010 xmlns:NS2=http://www.ncpdp.org/schema/SCRIPT> <NS2:Body> <NS2:New> <NS2:Pharmacy> <NS2:Identification> <NS2:ID>
I have the following XML: <SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/> <SOAP-ENV:Header> </SOAP-ENV:Header> <SOAP-ENV:Body> <MessageRequest></MessageRequest> </SOAP-ENV:Envelope> I am
hi i have an xml like this <?xml version=1.0?> <DataSetExchangeWMS xmlns=http://tempuri.org/DataSetExchangeWMS.xsd> <dtObjektInfo> <LanguageCode>1031</LanguageCode> <LiegenschaftID>7463</LiegenschaftID>
I have an SOAP response that looks similar to this: <?xml version=1.0 encoding=UTF-8?> <soapenv:Envelope
I have xml like this: <?xml version=1.0 encoding=utf-8?> <session xmlns=http://winscp.net/schema/session/1.0 name=blah@blah.com start=2011-10-03T15:09:30.481Z> <ls> <destination

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.