1

I'm trying to parse a HTML page using the HTML Agility Pack. I used a Firefox extension named XPath Checker and I'm rather sure that the expression is correct. However when I run my code, .NET tells me that "Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function."

That is fine except I have no idea where to get the Xslt or said Namespace from. How can I figure out what Namespace I need?

For reference, this is my code (I use MVC4):

List<Post> posts = new List<Post>();
            // Use this to count how many nodes to get
            int postNodesAmount = doc.DocumentNode.SelectNodes("//div[@class=\"post_block no_sidebar\" ]").Count;            

            for (int i = 1; i <= postNodesAmount; i++)
            {
                Post newPost = new Post();
                string newContent = doc.DocumentNode.SelectSingleNode("id('pane_forums:posts')/x:div/x:div[" + i + "]/x:div/x:div/x:div/x:p[1]").InnerText;
                newPost.Content = newContent;
                posts.Add(newPost);
            }

            return View(posts);
2
  • 1
    The Html Agility Pack XPATH implementation simply doesn't support queries involving namespaces. Commented Sep 6, 2013 at 15:01
  • Could you maybe make this an answer instead of a comment? :) Commented Sep 9, 2013 at 11:45

1 Answer 1

2

The Html Agility Pack XPATH implementation simply doesn't support queries involving namespaces.

The library is open source, so it can be changed, but this needs quite a bunch of rewrites to add this function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.