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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:16:25+00:00 2026-05-25T03:16:25+00:00

I want to parse the HTML of a website in my C# program. First,

  • 0

I want to parse the HTML of a website in my C# program.

First, I use the SGMLReader DLL to convert the HTML to XML. I use the following method for this:

XmlDocument FromHtml(TextReader reader)
{
    // setup SGMLReader
    Sgml.SgmlReader sgmlReader = new Sgml.SgmlReader();
    sgmlReader.DocType = "HTML";
    sgmlReader.WhitespaceHandling = WhitespaceHandling.None;
    sgmlReader.CaseFolding = Sgml.CaseFolding.ToLower;
    sgmlReader.InputStream = reader;

    // create document
    XmlDocument doc = new XmlDocument();
    doc.PreserveWhitespace = true;
    doc.XmlResolver = null;
    doc.Load(sgmlReader);
    return doc;
}

Next, I read a website and try to look for the header node:

var client = new WebClient();
var xmlDoc = FromHtml(new StringReader(client.DownloadString(@"http://www.switchonthecode.com")));
var result = xmlDoc.DocumentElement.SelectNodes("head");

However, this query gives an empty result (count == 0). But when I inspect the results view of xmlDoc.DocumentElement, I see the following:

VS watch

Any idea’s why there are no results? Note that when I try another site, like http://www.google.com, it works.

  • 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-25T03:16:26+00:00Added an answer on May 25, 2026 at 3:16 am

    You need to select using the namespace explicitly, see this question.

    XmlNamespaceManager manager = new XmlNamespaceManager(doc.NameTable);
    manager.AddNamespace("ns", "http://www.w3.org/1999/xhtml");
    
    doc.DocumentElement.SelectNodes("ns:head", manager);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to parse a html content that have something like this: <div id=sometext>Lorem<br>
Let's say this page www.example.com/mypage returns some html that I want to parse in
I want to use an html parser that does the following in a nice,
Possible Duplicate: How to parse and process HTML/XML with PHP? I want to grab
Possible Duplicate: How to parse HTML with PHP? i want to write a php-program
If I want to parse a HTML block using Nokogiri in Ruby like this:
I want to parse HTML with lxml using XPath expressions. My problem is matching
I want to parse some HTML in order to find the values of some
I want to parse the html table using html agility pack. I want to
I want to parse the html file, pdf file, csv file and text file.Now

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.