473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 1761


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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Pedro Hernandez | last post by:
Hello! I have some (many) text files produced on windows system that I need to process a bit, so I wrote a perl script to do the job. The files contains characters used in Spanish (e.g. ó, é,...
2
by: Genzo | last post by:
Hi all, was wondering if anyone might have knowledge on this. am testing with Opera 7.11. essentially whenever i try to use the substring "&lang=" in any string value in javascript, and try to...
6
by: Zhang Weiwu | last post by:
Hello. I am working with a php software project, in it (www.egroupware.org) Chinese simplified locate is "zh" while Traditional Chinese "tw". I wish to send correct language attribute in http...
2
by: santa19992000 | last post by:
Guys: Can somebody suggest a "C lang" project with pointers and linked lits for beginner?. Also is there anywahere I can find some C projects?. Thanks in advance.
37
by: Jan Wagner | last post by:
Hi, can't figure this one out, what's the CSS way to specify the language? In HTML it would be simply an lang="xx" attribute, or XHTML xml:lang="xx", but, how about in CSS? This would be...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.