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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:37:44+00:00 2026-06-15T02:37:44+00:00

I would like to find out why my code doesn’t work (or, get a

  • 0

I would like to find out why my code doesn’t work (or, get a piece of working sample code)

What I’m trying to do is to query an ASPX file using the HTMLAgilityPack, by an XPATH expression

This is the code, if you input //asp:content , you got 0 nodes
(Form1.designer.cs omitted for clarity):

using hap = HtmlAgilityPack;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Xml.Linq;
using System.Text;
using System.Windows.Forms;

namespace hap_shell
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            lbl_ErrMsg.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                lbl_ErrMsg.Text = "";
                hap.HtmlDocument doc = new hap.HtmlDocument();
                hap.HtmlWeb hw = new hap.HtmlWeb();

                doc.Load(txt_FilePath.Text);

                var q = doc.DocumentNode.Descendants("asp:Content");
                var cnt = q.Count();
                var nodes = q.ToList();
                var nav = doc.CreateNavigator();
                System.Xml.XmlNamespaceManager mgr = new System.Xml.XmlNamespaceManager(nav.NameTable);
                mgr.AddNamespace("asp",  "http://www.w3.org/1999/xhtml/"); // "http://tempuri.org/foo");
                var selNodes =nav.Select(txt_xpath.Text, mgr);


                //var selNodes = doc.DocumentNode.SelectNodes(txt_xpath.Text);

                if (selNodes == null)
                {
                    lbl_ErrMsg.Text = "No nodes match your query.";
                }
                lbl_ErrMsg.Text = selNodes.Count.ToString() + " nodes selected";
            }
            catch (Exception ex)
            {
                lbl_ErrMsg.Text = (ex.Message);
            }

        }
    }
}

this is the testing aspx, please save to a file, and input its full path to txt_FilePath:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="back_cal.aspx.cs" Inherits="EDP_SYS.back_cal" %>
    <asp:content id="Content1" contentplaceholderid="HeadContent" runat="server" >
        </asp:content>
        <asp:content id="Content2" contentplaceholderid="MainContent" runat="server">
         <table>

                <tr><td>
                <asp:button id="Button1" runat="server" text="Search"></asp:button></td></tr>

               </table> 
        </asp:content>

Note:

  1. I know that adding the namespace http://www.w3.org/1999/xhtml/ doesn’t make sense, please advise the correct way of adding the namespace
  2. It works when input is //tr, //td etc
  3. doc.DocumentNode.Descendants(“asp:Content”) works, but I need to accept a user-input XPath, so it won’t be considered (same for LiNQ for XML)
  • 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-15T02:37:45+00:00Added an answer on June 15, 2026 at 2:37 am

    Unfortunately, I wasn’t be able to make XmlNamespaceManager work with HtmlAgilityPack properly. But you can use xpath name() function to query asp:-like nodes. See:

    var contentNodes = doc.DocumentNode.SelectNodes("//*[name()='asp:content']");
    

    This will return 2 asp:content nodes from your fragment.

    But using of LINQ to XML is much easier for this.

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

Sidebar

Related Questions

I have been working through some code and I would like to work out
I would like to find out which version of an executable the CMD shell
I would like to find out is as3 is doing is doing anything in
I would like to find out if any and which database links are being
I would like to find out how can I convert touch coordinate that I
I would like to find out if a scrollView is scrolled up or down.
I'm learning about change listeners and would like to find out why a part
Hi I am new to AspectJ and I would like to find out if
I would like to know if there's a way in java to find out
I would like to find out and keep track of the 'line number' (rows)

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.