Extracting the XHTML "lang" parameter.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lucanos@gmail.com

    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

  • Martin Honnen

    #2
    Re: Extracting the XHTML &quot;lang&quot ; parameter.



    lucanos@gmail.c om wrote:

    [color=blue]
    > 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?[/color]

    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.docume ntElement.getAt tribute('lang')
    document.docume ntElement.getAt tribute('xml:la ng')
    should do.
    If it is parsed by an XML parser then for the lang attribute it should be
    document.docume ntElement.getAt tribute('lang')
    too, for the xml:lang attribute you need getAttributeNS as in the following

    document.docume ntElement.getAt tributeNS('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

    Comment

    Working...