c# - NameSpace Manager or XsltContent to parse aspx page -


How can I use the namespace manager or XSLT content to parse the aspx page?

I am using HtmlAgilityPack

I am trying to parse the aspx page to get the button and label control ID. When I try to select a node with the asp: button element, I get the following error

Here is the error message:

< Strong> Namespace Manager or XsltContext is required This query contains a prefix, variable, or user-defined function.

  HtmlAgilityPack.HtmlDocument htmldoc = new HtmlAgilityPack.HtmlDocument (); String filePath = @ "C: \ webform4.aspx"; Htmldoc.load (filepath); Foreach (html.doc.DocumentNode.SelectNodes ("// div") in HtmlNode div) {Response.Write (div.Id); HtmlNode ASP ("asp: button") in foreach (div.SelectNodes) {Response.Write (asp.Id); }}   

My aspx page looks like:

  & lt;% @page language = "c #" autoevolutionwireup = "true" codebahind = "Webform 4 Aspx.cs" Inheritance = "WebApplication 1.WebForm4"%> & Lt ;; DOCTYPE HTML PUBLIC "- // W3C // DTT XHTML 1.0 Transcription // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Head runat = "server" & gt; & Lt; Title & gt; & Lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form id = "form1" runat = "server" & gt; & Lt; Div id = "mydiv" & gt; & Lt; ASP: Button ID = "Button 1" Run = "Server" Text = "Button on Page4" /> & Lt; Br / & gt; & Lt; Br / & gt; & Lt; ASP: label ID = "label 1" run = "server" text = "label on page 4" & gt; & Lt; / Asp: Label & gt; & Lt; Br / & gt; & Lt; Br / & gt; & Lt; ASP: Button ID = "Button 2" Runat = "Server" Text = "Second Button Page 4" /> & Lt; Br / & gt; & Lt; ASP: Button ID = "Button 3" Runat = "Server" Text = "Second Button Page 4" /> & Lt; / Div & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;    

I use linux with the agility pack instead of the spread, about this How in

  HTMLAgilityPack HTML document htmlDoc = new HTMLGilityPack.HMML document (); String filePath = @ "C: \ webform4.aspx"; Htmldoc.load (filePath); Var aspNodes = htmlDoc.DocumentNode.Descendants (). Where (n = & gt; n.Name.StartsWith ("asp:")); Forever (var aspNode in aspNodes) {Console.WriteLine ("element: {0} ID: {1}", aspNodeName, aspNode.Attributes ["id"]. Value); }    

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -