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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:03:30+00:00 2026-05-26T17:03:30+00:00

I have XML exactly like this format: <?xml version=1.0 encoding=utf-8?> <book> <chapter> <verse>This is

  • 0

I have XML exactly like this format:

<?xml version="1.0" encoding="utf-8"?>
<book>
    <chapter>
        <verse>This is verse 1</verse>
        <verse>This is verse 2</verse>
        <verse>This is verse 3</verse>
        <verse>This is verse 4</verse>
    </chapter>
    <chapter>
        <verse>This is verse 1</verse>
        <verse>This is verse 2</verse>
    </chapter>
    <chapter>
        <verse>This is verse 1</verse>
    </chapter>
</book>

In C# using Linq, I need to be able to get the XML element of a specific position or index, based on the value of the function state.getChapterNumber(). For example, if the value were 4, I need to grab the 4th chapter element from the XML document.

XDocument book = XDocument.Load(string.Format("Translations/NWT/{0}.xml", state.BookName));
var verses = from chapter in book.Decendants()
             where state.getChapterNumber() == (WHAT DO I PUT HERE TO MATCH THE VALUE??)
             from verse in chapter.Descendants("p").Elements()
             select new
             {
                 VerseNumber = verse.Attribute("n").Value,
                 Text = verse.Value,
                 LastVerseInParagraph = verse.Parent.Elements().LastOrDefault().Value,
                 FirstVerseInParagraph = verse.Parent.Elements().FirstOrDefault().Value
             };

Please help, this is really important and has been holding me back for days. All I want to do is be able to get verses from any chapter set that I choose in the book.

  • 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-26T17:03:31+00:00Added an answer on May 26, 2026 at 5:03 pm

    Well to start with, I don’t think you wanted the second descendant overall – you wanted the second chapter, which isn’t necessarily the same thing. Fortunately it’s easy to do:

    // Use 1 for the second chapter, 2 for "element 2" (i.e. the third element) etc
    var chapter = book.Descendants("chapter").ElementAt(1);
    
    var verses = from verse in chapter...
    

    EDIT: For the verse number, use the overload of Select which provides the element index:

    var verses = chapter.Element("verse")
                        .Select((element, index) => new {
                                    VerseNumber = index + 1,
                                    Text = element.Value
                                });
    

    I don’t think it makes much sense for every verse to have the first and last verse in the paragraph, personally. It’s not really a feature of that verse, is it?

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

Sidebar

Related Questions

I would like to have an xml config file as follows: <?xml version=1.0 encoding=utf-8
I have XML that looks something like this: <Root xmlns=http://widgetspecA.com/ns> ...any... <WidgetBox> <A/> <B/>
I have XML that looks like this: <Parameter Name=parameter name Value=parameter value /> which
I have xml like this: <configurationData> <path name='b'> <path name='a'> <setting name='s1'> ![CDATA[XXXX]] </setting>
I have XML that looks like this: <ROW ref=0005631 type=04 line=1 value=Australia/> <ROW ref=0005631
I have XML like this: <assessment name=Assessment> <section name=Section1> <item name=Item1-1/> <item name=Item1-2/> <item
I have an XML document that looks like this: <file> <name>NAME_OF_FILE</name> </file> <file> <name>NAME_OF_FILE</name>
I have a button defined in my XML file. The button works exactly like
I have requested the data from our CGI in XML format. I do this
I have XML with a value like the following: <products> <product id=1 name=All Products>

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.