W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

Re: [DOM4] XML lang

From: Robin Berjon <robin@berjon.com>
Date: Wed, 5 Oct 2011 11:08:16 +0200
Cc: public-webapps <public-webapps@w3.org>
Message-Id: <DC618A60-D299-4EE3-8E69-7ADC847907E9@berjon.com>
To: Marcos Caceres <w3c@marcosc.com>
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

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:36 UTC