471,086 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 software developers and data experts.

Extracting the XHTML "lang" parameter.

Hi All,

I am toying with the idea of making a GreaseMonkey script, or similar
(depending on how far out of my comfort zone I am willing to venture),
which would translate a page automatically.

In order to trigger that script and pass the correct variable to the
translator, I am looking for a way to extract certain details from the
current page.

One of the pages I am looking at is XHTML, and I am wanting to extract
the "lang" (or maybe the "xml:lang") from the page.
In the source it is shown like this:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"
dir="ltr">

How would I reference that in JavaScript?

Any assistance or references that you may provide would be appreciated.

Luke

Sep 21 '05 #1
1 1669


lu*****@gmail.com wrote:

One of the pages I am looking at is XHTML, and I am wanting to extract
the "lang" (or maybe the "xml:lang") from the page.
In the source it is shown like this:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de"
dir="ltr">

How would I reference that in JavaScript?


It depends on whether the document is parsed by an HTML parser or an XML
parser, if it is parsed by an HTML parser then
document.documentElement.getAttribute('lang')
document.documentElement.getAttribute('xml:lang')
should do.
If it is parsed by an XML parser then for the lang attribute it should be
document.documentElement.getAttribute('lang')
too, for the xml:lang attribute you need getAttributeNS as in the following

document.documentElement.getAttributeNS('http://www.w3.org/XML/1998/namespace',
'lang')
That way in an XHTML document served as application/xhtml+xml both
Mozilla (tested with 1.7) as well as Opera (tested with 8.50) give the
value of the xml:lang attribute.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Pedro Hernandez | last post: by
2 posts views Thread by Genzo | last post: by
37 posts views Thread by Jan Wagner | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.