- From: Robin Berjon <robin@berjon.com>
- Date: Wed, 5 Oct 2011 11:08:16 +0200
- To: Marcos Caceres <w3c@marcosc.com>
- Cc: public-webapps <public-webapps@w3.org>
Hi Marcos, On Oct 5, 2011, at 10:14 , Marcos Caceres wrote: > 2. I need to check what the language of an element is (if any), without walking up the tree to look for an xml:lang attribute. Walking the tree is expensive, specially when XML says that xml:lang value is inherited by default. Unless you're dealing with documents of incredible depth, walking up the tree should really not be all that costly. What's more, since you're dealing with a tree that doesn't change, you can walk the tree once and precompute the language value for every element and cache it so that you only have to walk the tree once. But even without that note, have you looked at using document.querySelectorAll("element:lang(en-us)")? It doesn't do exactly what you want, but it should provide a decent starting place. If you're using XPath instead, it has a lang() function that does more or less the same thing. Oh, and happy birthday! -- Robin Berjon - http://berjon.com/ - @robinberjon
Received on Wednesday, 5 October 2011 09:08:46 UTC