HTML - XML y Javascript

 
Vista:
sin imagen de perfil

XML y Javascript

Publicado por Reecus (1 intervención) el 24/04/2014 22:44:12
que tal, tengo un proyecto que trata de hacer una simple pagina mostrando diferentes elementos html pero que se atribuyan mediante un archivo xml, osease poner un css mediante un xml.

la cosa es que no logro hacer que se lea mi xml para modificar los elementos,

este es mi archivo xml por el momento..

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="utf-8"?>
<h1>
	<size = "40px">
	<color = "blue">
</h1>
<parrafo>
	<padding></padding>
	<align></align>
	<color></color>
</parrafo>

y este es el codigo que eh tratado de utilizar para definir los css´s mediante el xml de arriba

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Proyecto 2do parcial - Encabezados</title>
 
<link rel="stylesheet" type="text/css" href="css/somestyle.css">
</head>
<body>
<script>
if (window.XMLHttpRequest){
  xmlhttp=new XMLHttpRequest();
}
else{
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
 
xmlhttp.open("GET","atributos.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;
 document.write("<style>");
   var x=xmlDoc.getElementsByTagName("h1");
     document.write(".h1mod{");
     document.write("font-size:"+x[0].getElementsByTagName("size")[0].nodeValue+";");
     document.write("color:"+x[0].getElementsByTagName("color")[0].nodeValue+";");
     document.write("}");
 document.write("<style>");
</script>
En este ejemplo indicamos que el elemento h1 tendra texto color azul y un tamaño de 40px
    <h1 class="h1mod">Prueba</h1>
</body>
</html>

simplemente la pagina no hace nada con el script que le pongo, una manita por favor
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 1.144
Oro
Ha mantenido su posición en HTML (en relación al último mes)
Gráfica de HTML

XML y Javascript

Publicado por xve (1543 intervenciones) el 08/05/2014 15:11:13
Hola Reecus, he estado mirando, y el error lo da es:
Uncaught TypeError: Cannot read property 'getElementsByTagName' of null
en la linea:
1
var x=xmlDoc.getElementsByTagName("h1");

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar