HtmlParser

Simple and fast crossplatform HTML/XML parser with a jQuery-like find() method. Also, contains a helper class to XML creating.
https://bitbucket.org/yar3333/haxe-htmlparser

To install, run:

haxelib install HtmlParser 3.3.1 

See using Haxelib in Haxelib documentation for more information.

README.md

HtmlParser haxe library

Light and fast HTML/XML parser with a jQuery-like find() method. Also, contains a helper class to XML creating.

Parsing HTML

In HTML mode parser ignore DOCTYPE and assume some tags self-closed (for example, <img> parsed as <img />).

var html = new HtmlDocument(File.getContent("myfile.html"));
var titles = html.find(">html>head>title");
trace(titles[0].innerHTML);
titles[0].innerHTML = "My New Title";
File.saveContent("myfile2.html", html.toString());

Tolerant Mode

To parse bad HTML you can use "tolerant" parser's mode:

var html1 = new HtmlDocument("<div><a>Link</div></a>", true); // wrong close tags sequence
var html2 = new HtmlDocument("<div><a>Link</div>", true); // missing '</a>'

Parsing XML

In XML mode parser is more strict: there are no self-closed tags allowed.

var xml = new XmlDocument(File.getContent("myfile.xml"));
var contents = xml.find(">root>items>content");
trace(contents[0].innerHTML);
contents[0].innerHTML = "New content for first item";
File.saveContent("myfile2.xml", xml.toString());

XML building

var doc = new XmlBuilder();
doc.begin("html");
    doc.begin("head");
        doc.begin("title").content("This is a title").end();
        doc.begin("meta")
				.attr("content", "text/html; charset=UTF-8")
				.attr("http-equiv", "content-type")
			.end;
    doc.end();
doc.end();

trace(doc.xml.find(">html>head").length); // direct access to created XmlDocument
trace(doc.toString()); // equals to `doc.xml.toString()`
Contributors
yar3333
Version
3.3.1
Published
3 weeks ago
License
LGPL

All libraries are free

Every month, more than thousand developers use haxelib to find, share, and reuse code — and assemble it in powerful new ways. Enjoy Haxe; It is great!

Explore Haxe

Haxe Manual

Haxe Code Cookbook

Haxe API documentation

You can try Haxe in the browser! try.haxe.org

Join us on Github!

Haxe is being developed on GitHub. Feel free to contribute or report issues to our projects.

Haxe on Github