question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Settings for parsing raw HTML, and how to get element path from root?

See original GitHub issue

Hi, I have two questions:

  1. If we were to parse some raw HTML, like new HtmlParser().Parse(html), where html is a string with some raw HTML as text (in UTF-8 or other relevant charset encoding), then are any other settings (options or configuration) needed to make the DOM parser work best/optimized?

  2. Given an element (IElement), is it possible to get its path or depth (from root)? For example, CsQuery can return a numeric array NodePath (code reference here), and other DOM parsers have similar APIs.

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
FlorianRapplcommented, Feb 2, 2017

There is the index helper. Just use Linq (Select) with the statement above?

From your example I assume you refer to elements (Children for indices. Otherwise the text nodes would be counted in).

myelement
  .Ancestors()
  .Where(node => node.ParentElement != null)
  .Select(element => element.ParentElement.Children.Index(element))
  .ToArray()
0reactions
FlorianRapplcommented, Feb 2, 2017

Glad I could help!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fetch HTML and insert into DOM, but parse relative to ...
I can fetch this file and insert it into the DOM easily: const dom = document.getElementById('root'); const response = await ...
Read more >
Parsing HTML in Node.js with Cheerio
Once you're done with parsing and manipulating your markup, you can access its root content with: $.root().html();.
Read more >
Parsing XML and HTML with lxml
Parsing XML and HTML with lxml. lxml provides a very simple and powerful API for parsing XML and HTML. It supports one-step parsing...
Read more >
Parsing HTML with Xpath
For HTML parsing, Xpath has some advantages over CSS selectors: ... our simple xpath simply describes a path from the root to the...
Read more >
A Roadmap to XML Parsers in Python
In this tutorial, you'll learn what XML parsers are available in Python and how to pick the right parsing model for your specific...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found