0

I am using Fizzler / HtmlAgilityPack to parse and extract elements from ASP.NET page file. In the asp.net file, we also use Telerik controls, e.g.

<telerik:RadGrid ... >

To extract this element , I used the methods below but not success. Can someone help on this please?

method#1:

HtmlDocument document = .....;

document.SelectNodes("telerik:RadGrid");

and it throws exception below:

Exception

Then I tried method#2:

XPathNavigator navigator = document.CreateNavigator();
var manager = new XmlNamespaceManager(navigator.NameTable);
manager.AddNamespace("telerik", "http://www.telerik.com");
var expr = XPathExpression.Compile("RadGrid");
expr.SetContext(manager);
var grids = document.DocumentNode.SelectNodes(expr);

There is no exception again. But grids is null even though the asp.net page contains markup of telerik:RadGrid.

Yang You
  • 2,618
  • 1
  • 25
  • 32

1 Answers1

1

It could be that your xpath is incorrect. Please try this //*[name()='telerik:RadGrid'] as a namespace, it should work for elements with XML Namespace.

Milan
  • 203
  • 2
  • 11
  • Thanks @Milan I tried this with method#1. It didn't throw out exception but the method still returns null for 'grids'. – Yang You Oct 15 '19 at 01:50
  • 1
    You could test the xpath in chrome or firefox console to make sure that it selects what you need. – Milan Oct 15 '19 at 06:55