jOOQ / jOOX

jOOX - The Power of jQuery Applied to W3C DOM Like JDBC, DOM is a powerful, yet very verbose low-level API to manipulate XML. The HTML DOM an be manipulated with the popular jQuery product, in JavaScript. Why don't we have jQuery in Java? jOOX is jQuery's XML parts, applied to Java.

Home Page:http://www.jooq.org/products

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Append child and get child's Match object

bagerman opened this issue · comments

Right now to construct

<books>
<book author="author1"/>
<book author="author2"/>
....
</books>

I'd do the following:

Match books = $("books");
for(i=0; i < 1000; i++) {
   books.append($("book").attr("author", "author" + i));
}

It appears that $(String name) is quite expensive call, probably due to the builder() call. Constructing the same document was 20 times slower than its parsing and profiling zeroed in on $("xxx") calls.

Is there a way to append a node to the existing Match object and get corresponding to the newly created node Match object back? I am thinking about doing something like this

books.append("book");
books.children().last().attr("author", "author" + i);

but am not sure if it's guarantied to get the last appended child.

Thanks for your suggestion. We're aware of this issue (#56). Thus far, we haven't yet fully thought through how to best resolve this. I like the API and would like to optimise only on the materialisation of the XML tree, not the API.

but am not sure if it's guarantied to get the last appended child.

Why not? If no one concurrently modifies your document? append() appends at the end, and children().last() provides the last child...

Closing this as a duplicate of #56