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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:01:49+00:00 2026-06-01T03:01:49+00:00

I am trying to parse the below XML in to the Entity through Linq,

  • 0

I am trying to parse the below XML in to the Entity through Linq, but i am not able to get the corresponding element.

<profile:learner type="" xmlns:profile="http://www.SumURL.com/XML/profile/2.0#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#">
  <profile:personal type="">
<profile:id>123</profile:id>
<vCard:Name rdf:parseType="Resource" type="">
  <vCard:FirstName>ABC</vCard:FirstName>
  <vCard:LastName>XYZ</vCard:LastName>
  <vCard:UserName>XYZ ABC</vCard:UserName>
  <vCard:FullName>ABC XYZ</vCard:FullName>
</vCard:Name>
<vCard:Address rdf:parseType="Resource" type="">
  <vCard:Street />
  <vCard:Extadd />
  <vCard:Locality />
  <vCard:Region />
  <vCard:PinCode />
</vCard:Address>
<vCard:TelephoneNumber />
<vCard:EmailId />
<vCard:TimeZone>(GMT-05:00) Eastern Time (US &amp; Canada)</vCard:TimeZone>
<vCard:Title />
<vCard:Organization rdf:parseType="Resource" type="">
  <vCard:OrgName>Q</vCard:OrgName>
</vCard:Organization>
<vCard:Role />
</profile:personal>
</profile:learner>
XNamespace env = xDoc.Root.Name.NamespaceName;
var a = (from level in xDoc.Descendants(env + "personal")
         select new 
         {
             PeopleID = (!string.IsNullOrEmpty(level.Elements(env + "id").First().Value)) ? level.Elements(env + "id").First().Value : String.Empty,
             FirstName = (!string.IsNullOrEmpty(level.Elements(env + "Name").Elements(env + "FirstName").First().Value)) ? level.Elements(env + "Name").Elements(rdf + "FirstName").First().Value : String.Empty,
         }).ToList();

I am able to get the PersonID but not the FirstName, Lastname, Role etc.

Please tell me where i am doing wrong in the above Linq Query.

Please help me out.

  • 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-01T03:01:50+00:00Added an answer on June 1, 2026 at 3:01 am

    As kjn pointed out, Name and FirstName elements are not in the profile namesapce, they are in vCard. And you have to reflect that in your code. You could also simplify your code a lot:

    XNamespace profileNs = "http://www.SumURL.com/XML/profile/2.0#";
    XNamespace vCardNs = "http://www.w3.org/2001/vcard-rdf/3.0#";
    var a = (from level in xDoc.Descendants(profileNs + "personal")
             select new
             {
                 PeopleID = (string)level.Element(profileNs + "id"),
                 FirstName = (string)level.Elements(vCardNs + "Name")
                                          .Elements(vCardNs + "FirstName")
                                          .FirstOrDefault()
             }).ToList();
    

    Note that this will sometimes set the properties to null, instead of string.Empty, but I think that makes more sense if the data is not present.

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

Sidebar

Related Questions

I am trying to parse the xml but its not returning anything here is
I am trying to parse the below xml in sql server to get all
i am trying to parse an xml element ( DItem >> Title ) below
Trying to parse some XML but apparently this is too much for a lazy
I'm trying to parse out the XML below with the PHP code shown here
I am trying to read the below xml file and get the name-value pairs
I am trying to parse a XML document using Xerces, but I cant seem
I'm trying to parse the XML below so that I wind up with an
I am trying to parse some currency data in xml format. Below code does
I am trying to parse an XML file as below <Subject> <chapter> <Question>abc</Question> <answer>avksn</answer>

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.