XML e Javascript
galera, como eu posso fazer isso?
caramba, eu fiz um script aqui, mas ele só funciona sem estar no servidor, tipo, estando na minha máquina, no c:, eu abro o html, e ele le o xml numa boa, mas qdo eu coloco o script no servidor, para ele ler o xml ele simplesmente nao consegue encontrar o arquivo :PPP!!! nao sei prq...
segue o código:
classXML.js
this.c_XML = function () { this.load = function (xml) { if (document.implementation && document.implementation.createDocument) { this.xmlDoc = document.implementation.createDocument("", "", null); //this.xmlDoc.onload = createTable; } else if (window.ActiveXObject) { this.xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); this.xmlDoc.onreadystatechange = function () { //if (this.xmlDoc.readyState == 4) createTable() }; } else { alert('Your browser can\'t handle this script'); return; } this.xmlDoc.load(xml); } this.GetNode = function (label) { x = this.xmlDoc.getElementsByTagName( this.getDSModulo() ); for (j=0;j<x[0].childNodes.length;j++) { var idiomas = x[0].childNodes[j]; if (idiomas.nodeName == this.getDSIdioma()) { for (i=0;i<idiomas.childNodes.length;i++) { if (idiomas.childNodes[i].getAttribute("id") == label) return idiomas.childNodes[i].firstChild.nodeValue; } } } } this.getDSIdioma = function () { return this.ds_idioma; } this.setDSIdioma = function (value) { this.ds_idioma = value; } this.getDSModulo = function () { return this.ds_modulo; } this.setDSModulo = function (value) { this.ds_modulo = value; }}classXML = new c_XML();classXML.setDSIdioma("espanhol");classXML.setDSModulo("forms");classXML.load("forms.xml");alert(classXML.GetNode("FormError");
forms.xml
<?xml version="1.0" encoding="ISO-8859-1"?><xml> <forms> <ingles> <label id="FormError"><![CDATA[The field {%field} is required!]]></label> <label id="InvalidField"><![CDATA[Invalid field {%field}!]]></label> <label id="DontMatch"><![CDATA[The fields {%field_1} and {%field_2} don't match!]]></label> <label id="MinLength"><![CDATA[The field {%field} must be at least {%number} characters!]]></label> </ingles> <espanhol> <label id="FormError"><![CDATA[O campo {%field} é obrigatório!]]></label> <label id="InvalidField"><![CDATA[Campo {%field} inválido!]]></label> <label id="DontMatch"><![CDATA[Os campos {%field_1} e {%field_2} não batem!]]></label> <label id="MinLength"><![CDATA[O campo {%field} tem que ter pelo menos {%number} characters!]]></label> </espanhol> </forms></xml>
n é erro de path, tipo, de eu nao saber aonde colocar o arquivo, prq eu já coloquei no diretorio publico, no mesmo diretorio aonde fica esse js, tirei o js de outro lugar(tipo, coloquei ele na mesma html, sem ser por src) e coloquei o xml no mesmo dir... caramba...
oq eu posso fazer gente, qual é o erro no script???
valeuu!!!
Discussão (4)
Carregando comentários...