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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:54:55+00:00 2026-06-08T18:54:55+00:00

Searching element of xml file using C# but getting following Error: Sequence contains no

  • 0

Searching element of xml file using C# but getting following

Error: Sequence contains no matching element

    XNamespace siteNM = "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0";
            XDocument sitemap = new XDocument
                (new XDeclaration("1.0", "UTF-8", null), 
                     new XElement(siteNM + "siteMap", 
                          new XElement(siteNM + "siteMapNode", new XAttribute("title", "Home"), new XAttribute("url", "home.aspx"), new XAttribute("description", "Home"))
                                 ));
    XElement x = sitemap.Root;

I have tried following two methods for searching element but both give me same error.

1st way:

XElement child = x.Descendants("siteMapNode").Where(el => el.Attribute("title") != null && el.Attribute("title").Value == "Home").First();

2nd Way:

XElement child1 = x.Descendants("siteMapNode").First(el => (string)el.Attribute("title") == "Home");

please help me.
Thank you so much..

  • 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-08T18:54:57+00:00Added an answer on June 8, 2026 at 6:54 pm

    missing namespace

    XElement child = x.Descendants(siteNM + "siteMapNode")
                    .First(el => el.Attribute("title") != null && el.Attribute("title").Value == "Home");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hoping this hasn't been asked before, but I have the following XML: <Company id=1000
I am trying to pull elements out of a parsed XML file by searching
Is it possible to find an xml element by searching with the value of
I have the following xml structure : <?xml version=1.0 encoding=utf-8 ?> <nws> <url>http://cpa.hypotheses.org/feed</url> <url>http://news.ycombinator.com/rss</url>
I'm using C# to handle an XML file with a repeating structure. The pseudo-document
I have been using normal file upload element to upload files and validate them.
For instance if I am searching by an element's attribute like id: soup.findAll('span',{'id':re.compile(^score_)}) I
I'm searching for a XPath expresssion, which gives me all grandchildren of an element.
Searching here I found that this question was already asked , but I think
This loads a set of values from an XML file and places them into

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.