HxQuery: A JQuery-like CSS Selectors engine written in Haxe, for quick visit any tree data structu

149 views
Skip to first unread message

Rocks Wang

unread,
May 20, 2013, 9:07:07 AM5/20/13
to haxe...@googlegroups.com

HxQuery is a JQuery-like CSS Selectors engine written in Haxe, for quick visit any tree data structure.
On Github: https://github.com/rockswang/hxquery

HxQuery provides an abstract TreeVisitor interface for developers to implement so that the custom tree struction can be operated with HxQuery engine. Currently the engine has already included:

  • An Xml visitor
  • A flash/nme display list visitor
  • A plain Haxe object visitor (very useful for parsed Json objects)

Play with display list demo for an intuitive understanding about this engine: https://github.com/rockswang/hxquery/blob/master/demo/hxquery-sample01.swf?raw=true
You can input any CSS selectors in bottom input field and click "Find" button to proceed the selectors matching against the display list tree starting rooting from Stage.
Valid selectors examples including: 
Stage Circle  -> all "Circle" in stage
Circle > Triangle -> all "Triangle" objects which are direct children of "Circle" objects
#circle2 Triangle -> all "Triangle" objects which are descendents of a DisplayObject with name "#circle2"
Stage .Base[name^='circle'] -> all objects derived from "Base" class (i.e. the super class of all 4 type of shapes) and with name starting with "circle"
Stage .ISmooth -> all objects implements "ISmooth" interface (i.e. Circle class& Round class)
:not(.ISmooth) -> all objects not implements "ISmooth" interface (i.e. Triangle class& Square class)

Xml example:

    var input: Xml = Xml.parse(ResKeeper.loadAssetText("res/a.xhtml"));
    var v: TreeVisitor<Xml> = new XmlVisitor();
    var query = new HxQuery(v);
    query.print(input);
    var found: Array<Xml> = query.find(input, "div#box1 > form input[type='text']");

Flash/NME display list example:

    var input = nme.Lib.current.stage;
    var v: TreeVisitor<DisplayObject> = new DisplayListVisitor();
    var query = new HxQuery(v);
    query.print(input);
    var found: Array<DisplayObject> = query.find(input, "MySprite > TextField:nth-child(2)");

Haxe object example:

    var input: Wrapper = DynamicVisitor.wrapper({ name: [ "rocks", "wang" ], age: 35, mobiles: [{ type: "xiaomi", no: "1111" }, { type: "c8500" }] });
    var v: TreeVisitor<Wrapper> = new DynamicVisitor();
    var query = new HxQuery(v);
    query.print(input);
    var found: Array<Wrapper> = query.find(input, "Array#mobiles > :not([no])");

yannick DOMINGUEZ

unread,
May 20, 2013, 9:46:06 AM5/20/13
to haxe...@googlegroups.com
Hi, that's cool !

Do you think it would make sense to have an HtmlElement implementation for the JS target ?

Thanks,
Yannick


2013/5/20 Rocks Wang <rock...@gmail.com>

--
To post to this group haxe...@googlegroups.com
http://groups.google.com/group/haxelang?hl=en
---
You received this message because you are subscribed to the Google Groups "Haxe" group.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Franco Ponticelli

unread,
May 20, 2013, 10:08:15 AM5/20/13
to haxe...@googlegroups.com
Very cool!

Rocks Wang

unread,
May 20, 2013, 10:21:26 AM5/20/13
to haxe...@googlegroups.com
So far I was not playing with JS target very often, but I think it should be easy, simply extends AbstractVisitor<HtmlElement>, and overrides parent, children, idOf, typeOf & hasClass methods, then HxQuery should work with DOM tree.

在 2013年5月20日星期一UTC+8下午9时46分06秒,yannick DOMINGUEZ写道:

Rocks Wang

unread,
May 20, 2013, 10:21:58 AM5/20/13
to haxe...@googlegroups.com
So far I was not playing with JS target very often, but I think it should be easy, simply extends AbstractVisitor<HtmlElement>, and overrides parent, children, idOf, typeOf & hasClass methods, then HxQuery should work with DOM tree.

在 2013年5月20日星期一UTC+8下午9时46分06秒,yannick DOMINGUEZ写道:
Hi, that's cool !

yannick DOMINGUEZ

unread,
May 20, 2013, 10:43:41 AM5/20/13
to haxe...@googlegroups.com

Thanks, I'll look into it.

Yannick

Justin Donaldson

unread,
May 20, 2013, 2:02:33 PM5/20/13
to Haxe
Very interesting... I've seen projects that try to throw out html selectors in order to make cross platform components from html elements... now it looks like you can bring selectors to arbitrary platforms, which could lead to different types of gui design.

-Justin
blog: http://www.scwn.net
twitter: sudojudo

Renaud Bardet

unread,
May 20, 2013, 2:18:50 PM5/20/13
to haxe...@googlegroups.com
this is cool !
I was researching that kind of syntax library to perform server-side HTML crawling,
it seems this generic Visitor implementation could be a good start, any idea or library to get a dom representation server-side ?

Rocks Wang

unread,
May 20, 2013, 10:43:59 PM5/20/13
to haxe...@googlegroups.com
Cocktail? http://www.silexlabs.org/haxe/cocktail/

在 2013年5月21日星期二UTC+8上午2时18分50秒,Renaud Bardet写道:

yannick DOMINGUEZ

unread,
May 21, 2013, 5:37:15 AM5/21/13
to haxe...@googlegroups.com
Yes it should do the trick. It's meant for flash/NME first but we've built it for PHP and for macros too.


2013/5/21 Rocks Wang <rock...@gmail.com>

Renaud Bardet

unread,
May 21, 2013, 11:57:18 AM5/21/13
to haxe...@googlegroups.com
Wow, I didn't know about cocktail, that's great work !
I'm definitely using that in future projects, layouting in HTML seems to be a usefull idea

yannick DOMINGUEZ

unread,
May 21, 2013, 1:57:20 PM5/21/13
to haxe...@googlegroups.com

Thanks, I hope you'll like it !

Reply all
Reply to author
Forward
0 new messages