csss

CSS-Selector With a Modified Xml Parser(with the position info)
https://github.com/R32/css-selector/

To install, run:

haxelib install csss 0.3.3 

See using Haxelib in Haxelib documentation for more information.

README.md

CSS Selector

CSS-Selector With a Modified Xml Parser

  • Provide extra position info that can be used to locate invalid value/attr(optional)

If the position is not accurate(in flashdevelop). You may need add -D old-error-format

  • Not based on RegExp, No Dependencies

  • Ease To Use.

use .querySelector/one or .querySelectorAll/all to query XML. e.g. xml.all("a:not([href='#'])").

supported descendant selector:

` E : supported E F : supported E > F : supported E + F : supported Note: Partial E ~ F : supported Note: Partial`

supported pseudo-classes/element in Selector.hx

  • -D NO_UPPER: Keep tagName case

example:

import csss.xml.Xml;
using csss.Query;

class Main {
    static function main() {
        mymacro();
    }

    macro static function mymacro() {
        var myxml = "bin/index.html";
        var file = sys.io.File.getContent(myxml);
        var body = Xml.parse(file).querySelector("body");

        var x = body.querySelector("#t3 > li span");                         // equal body.one("#t3 > li span")
        trace(x != null ? x.toSimpleString() : x);

        var a = body.querySelectorAll(".selector-test > :nth-child(2n+1)");  // equal body.all("...")
        for (x in a) {
            trace(x.toSimpleString());
        }
        var attr = body.get("class");
        if (attr != "expected") {
            var p = body.attrPos("class");                                   // got position of attr
            var pos = haxe.macro.PositionTools.make({
                min: p,
                max: p + attr.length,
                file: myxml
            });
            haxe.macro.Context.error("click this message to location where the error occurred.", pos);
        }
        return macro null;
    }
}

Issues

  • [Insolvable] Do not suport escaped single/double quotes.

e.g: a[title="hi \"name\"."] will get a unexpected value.

  • Do not suport two consecutive + or ~.

Invalid: "li + li + li", "li ~ li ~ li", "li + li ~ li", "li ~ li + li"

Available: "li + li > li", "li + li li", "li li + li", "li > li > li"

Changes

  • 0.3.3: clearup
  • 0.3.2:
  • make xml.attributeMap to Array
  • remove escape and StringBuf from Xml.parse
  • 0.3.1:
  • Added :last-child for Querying.
  • Allow tag <IMG> without /.
  • Ignoring all spaces TextNode of Xml
  • 0.3.0: fix class validating of Query. more...
  • 0.2.2: added Xml.parse that you no longer need to import csss.xml.Parse
Contributors
r32
Version
0.3.3
Published
4 weeks ago
License
MIT

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