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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:20:43+00:00 2026-05-27T18:20:43+00:00

I would like to get some specific values in a (x)html file using an

  • 0

I would like to get some specific values in a (x)html file using an xpath statement.
I read the html file like an xml file using the xmlDocument class.
Problem is that my xpath query doesn’t work because of the namespace defined in the html tag:

<html xmlns="http://www.w3.org/1999/xhtml">

If I remove the xmlns in the html tag, it works fine.
What’s wrong?
(I don’t want to use the Html Agility Pack)
Thanks!
Here’s my code:

XmlDocument readDoc = new XmlDocument();
System.Xml.XmlNamespaceManager xmlnsManager = new System.Xml.XmlNamespaceManager(readDoc.NameTable);
readDoc.XmlResolver = null;
xmlnsManager.AddNamespace("html", "http://www.w3.org/1999/xhtml");
readDoc.Load("myHTML.html");
int count = readDoc.SelectNodes("//html/body/div/span[@class='layout']",xmlnsManager).Count;
  • 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-27T18:20:44+00:00Added an answer on May 27, 2026 at 6:20 pm

    Since your element is in the namespace, your XPath statement must include the namespace too (including for the sub-elements)…

    int count = readDoc.SelectNodes("//html:html/html:body/html:div/html:span[@class='layout']",xmlnsManager).Count;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ElementTree to successfully pull values from specific tags in an xml file.
I would like to understand the values I get from read command in console.
I would like to describe some specifics of my program and get feedback on
I would like to get some of your ideas about resource name / categorizing
I would like to get some information on list of points that needs to
I would like to get some feedback on what is one of my first
I would like to get some nested params. I have an Order that has
What I would like to get some input on is how to remove certain
I'm a lone developer who would like to get some structure to my projects.
I am running C# framework 2.0 and I would like to get some of

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.