Hello,

First of all, I'm new with Jquery.

I would like to use an xml file to translate a website. For the moment
I use "pure javascript", but the problem is that it's fonctionnal with
IE6&7, FF2 and Opera, but not with Safari (Mac).

So, I would like to use now Jquery to do the same thing because Jquery
is compatible with Safari.


My actual code :


XML file : chineese.xml
---------------------------------

<prompt>
<IpAddress>Ip 地址 :</IpAddress>
<SubNetMask>子网隐码 :</SubNetMask>
<English>English :</English>
<French>French :</French>
<German>German :</German>
</prompt>

HTML file :
---------------

<html>
<head><script language="javascript" src="translation.js"></script></
head>
<body onload="loadXML()">
<span id="IpAddress"></span> 195.168.10.20 <br>
<span id="SubNetMask"></span> 255.255.255.0 <br>
</body>
</html>

Translation.js :
--------------------

function loadXML()
{
    if (window.ActiveXObject)
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async=false;
        xmlDoc.load(chineese.xml);
        translateall();
    }
    else if (document.implementation &&
document.implementation.createDocument)
    {
        xmlDoc = document.implementation.createDocument("","",null);
        xmlDoc.load(chineese.xml);
        xmlDoc.onload = translateall;
    }
    else
    {
        alert('Your browser cannot handle this script');
    }
}

function translateall()
{
    var elem;
    var Prompts = new Array;
    var x = xmlDoc.documentElement;

    for (i=0 ; i<x.childNodes.length ; i++)
    {
        Prompts[i] = x.childNodes[i].nodeName;
    }

    for (i=0; i<Prompts.length; i++)
    {
        elem = document.getElementById(Prompts[i]);
        if (elem)
            document.getElementById(Prompts[i]).innerHTML =
xmlDoc.getElementsByTagName(Prompts[i])[0].childNodes[0].nodeValue;
    }
}


I couldn't find a way using jQuery to get the tagName of an element.
Someone can help me ?

I can use the following code to find the contain of a node but it's
not that I want to do because it's a "static method":

$(function()
{

$.get("chineese.xml", function(xml)
{
  var IpAddress = $("IpAddress", xml).text();
  $("div#IpAddress").html(IpAddress);
});

});


Thanks in advance

Benoit - www.survoldefrance.fr/index.php?lang=UK

Reply via email to