WHtmlParser was creating to parse HTML code as fast as possible. Parser does not have limitations imposed by parsers according to a WC3 specification. Example you can put any tag in any place and nothing will be added automatically.
If you want to parse and modify a HTML code in an object-oriented way I recommend using a
WQuery library which wraps a parser into an object, which shares user-friendly methods similar to those in
WQuery but also
WHtmlParser are a part of the Wojdav Bootstrap Mvc library and subject to the same license conditions.
See the parser limitations before using it.
A HTML code must be correct, otherwise, will be thrown an exception. A parser will not add or close automatically the missing tags. We can create
Values of the attributes must be given in a quotation mark (
A parser does not parse attributes with a value given in a single quotation mark or with no limitation marks. Both cases end with an exception:
A parser parses a
All limitations will be gradually removed as the library will be developed.
If you want to parse considerable pages of the unknown origin I recommend a
We create a parser object which after parsing a HTML code returns a list of nodes and on which we can induce subsequent methods. In this case, we add a class, an
id attribute and another element to the element.
The use of a parser
var htmlParser = new HtmlParser(); IList<INode> list = htmlParser.Parse("<div></div>"); var element = list as IElement; element.ClassList.Add("myClass"); element.Attributes.SetNamedItem("id", "myID"); element.AppendChild(new Element("p").AppendChild(new TextNode("Welcome"))); Console.WriteLine(element.ToHtml());
When we use a
ToHtml method on the element, a parsed and modified code will be returned as a HTML code.
Result of a
<div class="myClass" id="myID"> <p>Welcome</p> </div>