Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get a custom tag with html agility pack?

Need to create a summary/indice

For this I have tags <Document-Title> My Title </Document-Title>

How I get these tags using HTML agility pack?

I have tried this:

 HtmlDocument html = new HtmlDocument();
  html.Load(new StringReader(Document.Content)); //Is the <html> I'm load in database

  var titles = html.DocumentNode.SelectNodes("//Document-Title");

But titles is null

like image 257
Rod Avatar asked Mar 11 '15 18:03

Rod


1 Answers

Just use //document-title , it jsut need to be lowercase, HAP lowercases the tags by default, i believe the reason is that xHTML required the tag names to be lower-case, so HAP probably considered that, but its not specific to standard HTML, its fine to use tags with capitalization.

Update: after some research lower case is an xpath requirement, HAP is case insenstive on its own and does not care about XHTML.

like image 69
Xi Sigma Avatar answered Oct 05 '22 22:10

Xi Sigma