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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:50:14+00:00 2026-05-31T09:50:14+00:00

I am thinking I am doing something wrong here. I am using XDocument.Descendants to

  • 0

I am thinking I am doing something wrong here. I am using XDocument.Descendants to get a grandchild element of an xml file that I am trying to parse into an object. But I am getting a null value every time I attempt to run it.

IEnumerable<PatientClass> template = (IEnumerable<PatientClass>)(from templates in xDocument.Descendants("dataTemplateSpecification")
select new PatientClass
{
  PatientId = int.Parse(templates.Descendants("element").Single(el => el.Attribute("name").Value=="PatientId").ToString()),
  EMPIID = int.Parse(templates.Descendants("element").Single(el => el.Attribute("name").Value=="EMPIID").ToString())                  
});

Let us suppose that that was the extent of the linq query that I am using…

<dataTemplateSpecification id="id1" name="name1" >
<templates xmlns="">
<template>
  <elements>
    <element id="element0" name="PatientId" display="Patient ID" dataType="String" visable="true" readOnly="false" value="4563">
      <mapping path="//Template/TemplateData/ACOData/PATIENT_ID" />
    </element>
    <element id="element1" name="PopulationPatientID" display="Population Patient ID" dataType="String" visable="true" readOnly="true" enc="2098" value="6407">
      <mapping path="//Template/TemplateData/ACOData/POPULATION_PATIENT_ID" />
    </element>
    <element id="element2" name="EMPIID" display="EMPIID" dataType="String" visable="true" readOnly="true" value="">
      <mapping path="//Template/TemplateData/ACOData/EMPI" />
    </element>        
  </elements>
</template>
</templates>
</dataTemplateSpecification>

Let us suppose that that is the xml that I am using… now, would I need namespaces to get that above query to work? I hope not. that would mean that I would have to rewrite my xml… Which would really, really be rough for me.

  • 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-31T09:50:16+00:00Added an answer on May 31, 2026 at 9:50 am

    I’m not really sure what you’re trying to do. It looks like you’re trying to parse an XML element to an integer. The below code works for me, but I had to give the element with name EMPIID an integer in the value attribute.

    Please note, though, that there is probably a better way to do what you’re trying to do. I just tried to get as close to your original code as possible with my example.

    var xel = System.Xml.Linq.XElement.Parse(xml);
    var elements = xel.Descendants("elements");
    
    var patients = elements.Select(e => new
    {
        PatientID = int.Parse(e.Elements("element")
            .First(el => el.Attribute("name").Value == "PatientId")
            .Attribute("value").Value),
        EMPIID = int.Parse(e.Elements("element")
            .First(el => el.Attribute("name").Value == "EMPIID")
            .Attribute("value").Value)
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I might be doing something completely wrong here but for some reason the values
i think i'm doing something wrong. i mean, I'm trying to make a function
I'm doing PHP development and I'm thinking of using one of these. I have
Thinking that the answer to this is pretty obvious but here it goes: When
EDIT: I think i asked something really wrong over here, and i am sorry.
I was thinking of doing a head request with cURL, was wondering if this
Thinking about a Windows-hosted build process that will periodically drop files to disk to
Thinking about avoiding code replication, I got a question that catches me every time
So I have a Sinatra app that receives an XML via a HTTP POST
I am trying to create a script that walks a directory and renames files.

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.