
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
A utility to convert html document into a tree of HtmlNode elements. It can also parse the css styles and apply to the html elements
MariGold.HtmlParser is a utility to parse the HTML documents into a collection of IHtmlNode type instances. You can either traverse through the document by parsing every root elements one by one or parse the entire document at once. Once an HTML element parsed, it will recursively parse all the child elements.
In Package Manager Console, enter the following command:
Install-Package MariGold.HtmlParser
MariGold.HtmlParser can be used to parse both HTML and CSS of an HTML document.
In the following example, the first loop iteration will parse the first div and the following div in the second and final iteration.
using MariGold.HtmlParser;
HtmlParser parser = new HtmlTextParser("<div>first</div><div>second</div>");
while (parser.Traverse())
{
IHtmlNode node = parser.Current;
}
To parse the entire document at once, use Parse method. It will parse all the HTML elements in the given document and Current property will point to the first root element
if (parser.Parse())
{
IHtmlNode node = parser.Current;
}
Use Next and Previous properties to travel through the IHtmlNode collection. Use the Children property to access the descendant elements.
IHtmlNode node = parser.Current;
while (node != null)
{
node = node.Next;
}
By default parsing HTML will not parse the CSS styles. The ParseStyles method will parse any external or inline styles in the document. The parsed styles can be accessed using the Styles and InheritedStyles properties of IHtmlNode.
HtmlParser parser = new HtmlTextParser(@"<html>
<head>
<style type='text/css'>
.cls
{
font-size:10px;
}
</style>
</head>
<body>
<div class='cls' style='font-family:Arial'>sample</div>
</body>
</html>");
if (parser.Parse())
{
await parser.ParseStylesAsync();
}
To resolve any protocol free or relative url of external style sheets, use the UriSchema and BaseURL properties.
parser.UriSchema = Uri.UriSchemeHttp;
parser.BaseURL = "http://site.com";
FAQs
A utility to convert html document into a tree of HtmlNode elements. It can also parse the css styles and apply to the html elements
We found that marigold.htmlparser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.