Ver Mensaje Individual
  #7 (permalink)  
Antiguo 27/05/2012, 21:56
Avatar de djaevi
djaevi
 
Fecha de Ingreso: marzo-2007
Ubicación: Moreno, Buenos Aires
Mensajes: 400
Antigüedad: 18 años
Puntos: 47
Respuesta: Leer fichero XML

Hola te tengo buenas noticias investigando un poco he sacado una posible solucion al menos lo probe en mozilla y chrome y funciona ahi va el codigo:

Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>Documento sin título</title>
  5. <script type="text/javascript">
Código Javascript:
Ver original
  1. var xmlDoc;
  2.     function loadXML() {
  3.       xmlDoc=document.implementation.createDocument("","",null);
  4.       xmlDoc.load("archivo.xml");
  5.       xmlDoc.onload= readXML;
  6.     }
  7.  
  8.     function readXML() {
  9.         var nombre = document.usuarios.nombre.value;
  10.         var apellido = document.usuarios.apellido.value;
  11.         var root = xmlDoc.documentElement;
  12.         for (var i=0; i<root.childNodes.length; i++) {
  13.             var checkNombre = false;
  14.             var checkApellido = false;
  15.             if (root.childNodes[i].tagName == "persona") {
  16.                 for (var j=0; j<root.childNodes[i].childNodes.length; j++) {
  17.                     if ((root.childNodes[i].childNodes[j].tagName == "nombre") && (root.childNodes[i].childNodes[j].textContent == nombre)) {
  18.                         checkNombre = true;
  19.                         }
  20.                     if ((root.childNodes[i].childNodes[j].tagName == "apellido") && (root.childNodes[i].childNodes[j].textContent == apellido)) {
  21.                         checkApellido = true;
  22.                         }
  23.                     }
  24.                 }
  25.                 if ((checkNombre) && (checkApellido)) {
  26.                     alert("Esta Persona Ya Esta Registrada");
  27.                     break;
  28.                     }
  29.             }
  30.         if ((!checkNombre) || (!checkApellido)) {
  31.             alert("Esta Persona No Existe");
  32.             }
  33.      }
Código HTML:
Ver original
  1. </head>
  2.  
  3. <body">
  4.     <form name="usuarios" method="post" action="#">
  5.         Nombre: <input type="text" name="nombre" /><br />
  6.         Apellido: <input type="text" name="apellido" /><br /><br />
  7.         <input type="button" onclick="loadXML();" value="Comprobar"; />
  8.     </form>
  9. </body>
  10. </html>

Y aqui el xml, por lo que he visto no dejes espacios en blanco solo saltos de linea y tabulaciones.

Código XML:
Ver original
  1. <?xml version="1.0" encoding="UTF-8"?>
  2.     <personas>
  3.         <persona id="001" >
  4.             <nombre>Pablo</nombre>     
  5.             <apellido>Perez</apellido>
  6.         </persona>
  7.         <persona id="002">
  8.             <nombre>Diego</nombre>     
  9.             <apellido>Garcia</apellido>
  10.         </persona>
  11.     </personas>

Saludos