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

  • Home
  • SEARCH
  • 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 7033639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:05:24+00:00 2026-05-28T01:05:24+00:00

I have a complicated xml file and in different levels the following part may

  • 0

I have a complicated xml file and in different levels the following part may exist:

<ChrNote>
  <note>The appropriate character is:</note>
</ChrNote>
<ChrDef>
  <extension char="A">initial</extension>
  <extension char="D">subsequent</extension>
  <extension char="G">subsequent delayed</extension>
  <extension char="S">sequel </extension>
</ChrDef>
...

and here is the code snippet that I use to build a text file:

var lv1s = from lv1 in XMLDoc.Descendants("chapter").DescendantsAndSelf()
           select new
           {
               SChar = (string)lv1.Element("ChrNote") ?? "",
               SCharDef = (string)lv1.Element("ChrDef") ?? "",
               //Returns only first attribute ..?
               CharLetter = (lv1.Element("ChrDef") == null ? "" : 
                            (string)(lv1.Element("ChrDef")
                                        .Element("extension")
                                        .Attribute("char")) ?? "")
           };

The problem is that the above query returns only the first attribute (“A”) from element “extension”. I have no experience in linq and any help will be 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-28T01:05:25+00:00Added an answer on May 28, 2026 at 1:05 am

    Is this what you are looking for?

    var result = from x in XMLDoc.Descendants("chapter")
                 let Definitions = x.XPathSelectElements("ChrDef/extension")
                 select new
                 {
                     Note = x.XPathSelectElement("ChrNote/note") == null ? "" : x.XPathSelectElement("ChrNote/note").Value,
                     Definitions = Definitions.Select(y=> new { Extension = y.Value, Char = y.Attribute("char").Value })
                 };
    
    Console.WriteLine ("{0}", result.First().Note);
    foreach (var definition in result.First().Definitions)
    {
        Console.WriteLine ("{0}, {1}", definition.Extension, definition.Char);
    }
    

    This will give you the following output:

    The appropriate character is:
    initial, A
    subsequent, D
    subsequent delayed, G
    sequel , S
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't believe how unbelievably complicated this has been... I have the following XML...
I have the following XML file: <xml version=1.0 encoding=utf-8?> <Data> <Parameter1>1</Parameter1> </Data> I want
We have an odd problem, we are tranforming a pretty complicated XML file using
I have a complicated structure to be displayed on the screen. Made with XML
We have an XML file with a very simple implementation of XLink : <root
I have a series of complicated XML files from Amazon showing order reports. A
Let's say I have an XML file that looks like this: <a id=x> <b>
I have a complicated XML and I am trying to write a XSL transformation
I'm working with a complicated xml schema, for which I have created a class
So, the noobie question of the day... I have an XML file with the

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.