8
Convertir archivo XML a HTML con PHP Estructura no_guia.xml

Convertir archivo xml a html con php

Embed Size (px)

DESCRIPTION

Convertir archivo xml a html con php

Citation preview

Page 1: Convertir archivo xml a html con php

Convertir archivo XML a HTML con PHP

Estructura no_guia.xml

Page 2: Convertir archivo xml a html con php

Código PHP

Page 3: Convertir archivo xml a html con php

Resultado:

Código:

1.- No_guia.xml

<?xml version="1.0" encoding="utf-8"?><pma_xml_export version="1.0" xmlns:pma="http://www.phpmyadmin.net/some_doc_url/"> <database name="e-dbase"> <table> <idguia>1</idguia> <order_number>31e003</order_number> <numguia>116666</numguia> <exportado>1</exportado> </table> <table> <idguia>2</idguia> <order_number>TOSHI000000000005-1</order_number> <numguia>116661</numguia> <exportado>1</exportado> </table> <table> <idguia>3</idguia> <order_number>TOSHI000000000006-1</order_number>

Page 4: Convertir archivo xml a html con php

<numguia>116662</numguia> <exportado>1</exportado> </table> <table> <idguia>4</idguia> <order_number>TOSHI000000000007-1</order_number> <numguia>11663</numguia> <exportado>1</exportado> </table> <table> <idguia>5</idguia> <order_number>TOSHI000000000012-1</order_number> <numguia>116665</numguia> <exportado>1</exportado> </table> <table> <idguia>6</idguia> <order_number>TOSHI000000000013-1</order_number> <numguia>116669</numguia> <exportado>1</exportado> </table> </database></pma_xml_export>

2.- Archivo.php

<html><body><head> <style type="text/css"> body { color: purple; background-color: #d8da3d }

h1 { font-family: Helvetica, Geneva, Arial, SunSans-Regular, sans-serif }

Page 5: Convertir archivo xml a html con php

</style></head><script>if (window.XMLHttpRequest) {// Código para soportar los diferentes navegadores IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// Código para los vavegadores IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } //cargamos el nombre del archivo XML a procesar en este caso: no_guia.xml xmlhttp.open("GET","no_guia.xml",false);xmlhttp.send();xmlDoc=xmlhttp.responseXML;//Insdertamremos los datos en una tabladocument.write("<table border='1'>");// El tag a procesar es tabla y dentro de cada tag tabla existen otros tags var x=xmlDoc.getElementsByTagName("table");for (i=0;i<x.length;i++) { document.write("<TITLE>Importar XML a HTML</TITLE>"); document.write("<tr><td>"); //Definimos el color y tamaño del texto document.write("<font color='red' size=4>"); document.write("<strong>"); document.write(x[i].getElementsByTagName("idguia")[0].childNodes[0].nodeValue); document.write("</strong>"); document.write("</font>"); document.write("</td><td>");

Page 6: Convertir archivo xml a html con php

document.write("<td>"); document.write("<strong>"); //Definimos tipo de fuente para el texto HTML document.write("<font face='Comic Sans MS,arial,verdana'>"); document.write(x[i].getElementsByTagName("order_number")[0].childNodes[0].nodeValue); document.write("</strong>"); document.write("</font>"); document.write("</td><td>"); document.write("<strong>"); document.write(x[i].getElementsByTagName("numguia")[0].childNodes[0].nodeValue); document.write("</strong>"); document.write("</td><td>"); document.write(x[i].getElementsByTagName("exportado")[0].childNodes[0].nodeValue); document.write("</td></tr>"); } // Cerramos la tabladocument.write("</table>");</script></body></html>