¿Cómo se puede utilizar XML ?
XML se utiliza en muchos aspectos del desarrollo web.
XML se usa a menudo para separar los datos de la presentación.
XML separa los datos de la presentación
XML no contiene ninguna información sobre cómo se mostrará.
Los mismos datos XML se pueden utilizar en muchos escenarios de presentación diferentes.
Debido a esto, con XML, existe una separación completa entre datos y presentación.
XML suele ser un complemento de HTML
En muchas aplicaciones HTML, XML se usa para almacenar o transportar datos, mientras que HTML se usa para formatear y mostrar los mismos datos.
XML separa los datos de HTML
Al mostrar datos en HTML, no debería tener que editar el archivo HTML cuando cambien los datos.
Con XML, los datos se pueden almacenar en archivos XML separados.
Con unas pocas líneas de código JavaScript, puede leer un archivo XML y actualizar el contenido de datos de cualquier página HTML.
Libros.xml
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book
category="cooking">
<title lang="en">Everyday
Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="children">
<title lang="en">Harry
Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="web">
<title lang="en">XQuery
Kick Start</title>
<author>James McGovern</author>
<author>Per Bothner</author>
<author>Kurt Cagle</author>
<author>James Linn</author>
<author>Vaidyanathan
Nagarajan</author>
<year>2003</year>
<price>49.99</price>
</book>
<book category="web"
cover="paperback">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>
Aprenderá mucho más sobre el uso de XML y JavaScript en la sección DOM de este tutorial.
Datos de la transacción
Existen miles de formatos XML, en muchas industrias diferentes, para describir las transacciones de datos del día a día:
- Acciones y participaciones
- Transacciones financieras
- Datos médicos
- Datos matemáticos
- Mediciones científicas
- Información de noticias
- Servicios meteorológicos
Ejemplo: XML Noticias
XMLNews es una especificación para intercambiar noticias y otra información.
El uso de un estándar facilita tanto a los productores de noticias como a los consumidores de noticias producir, recibir y archivar cualquier tipo de información de noticias en diferentes lenguajes de programación, hardware y software.
Un ejemplo de documento XMLNews:
<?xml version="1.0" encoding="UTF-8"?>
<nitf>
<head>
<title>Colombia Earthquake</title>
</head>
<body>
<headline>
<hl1>143 Dead in Colombia Earthquake</hl1>
</headline>
<byline>
<bytag>By Jared Kotler, Associated Press Writer</bytag>
</byline>
<dateline>
<location>Bogota, Colombia</location>
<date>Monday January 25 1999 7:28 ET</date>
</dateline>
</body>
</nitf>
Ejemplo: servicio meteorológico XML
Un servicio meteorológico nacional XML de la NOAA (Administración Nacional Oceánica y Atmosférica):
<?xml version="1.0" encoding="UTF-8"?>
<current_observation>
<credit>NOAA's National Weather Service</credit>
<credit_URL>http://weather.gov/</credit_URL>
<image>
<url>http://weather.gov/images/xml_logo.gif</url>
<title>NOAA's National Weather Service</title>
<link>http://weather.gov</link>
</image>
<location>New York/John F. Kennedy Intl Airport, NY</location>
<station_id>KJFK</station_id>
<latitude>40.66</latitude>
<longitude>-73.78</longitude>
<observation_time_rfc822>Mon, 11 Feb 2008 06:51:00 -0500 EST
</observation_time_rfc822>
<weather>A Few Clouds</weather>
<temp_f>11</temp_f>
<temp_c>-12</temp_c>
<relative_humidity>36</relative_humidity>
<wind_dir>West</wind_dir>
<wind_degrees>280</wind_degrees>
<wind_mph>18.4</wind_mph>
<wind_gust_mph>29</wind_gust_mph>
<pressure_mb>1023.6</pressure_mb>
<pressure_in>30.23</pressure_in>
<dewpoint_f>-11</dewpoint_f>
<dewpoint_c>-24</dewpoint_c>
<windchill_f>-7</windchill_f>
<windchill_c>-22</windchill_c>
<visibility_mi>10.00</visibility_mi>
<icon_url_base>http://weather.gov/weather/images/fcicons/</icon_url_base>
<icon_url_name>nfew.jpg</icon_url_name>
<disclaimer_url>http://weather.gov/disclaimer.html</disclaimer_url>
<copyright_url>http://weather.gov/disclaimer.html</copyright_url>
</current_observation>