1- QUE SIGNIFICA Y PARA QUE FUE DISEÑADO XML
2- Ejemplo XML:
>?xml version="1.0" encoding="UTF-8"?> >note> >to>Tove>/to> >from>Jani>/from> >heading>Reminder>/heading> >body>Don't forget me this weekend!>/body> >/note>
3- ¿Por qué estudiar XML?
4- Normas XML importantes
5- ¿Qué es el XML?
6- La diferencia entre XML y HTML
7- ¿Cómo se puede usar XML ?
8- Árbol XML
9- Estructura de árbol XML
>root>
>child>
>subchild>.....>/subchild>
>/child>
>/root>10- Sintaxis de autodescripción
> title lang=”en”>Everyday Italian>/title>
author>Giada De Laurentiis>/author>
year>2005>/year>
price>30.00>/price>
Puede suponer, a partir de este ejemplo, que el documento XML contiene información sobre libros en una librería.
11- Reglas de sintaxis XML:
1) Los documentos XML deben tener un elemento raíz. Los documentos XML deben contener un elemento raíz que sea el padre de todos los demás elementos:
>root>
>child>
>subchild>.....>/subchild>
>/child>
>/root>
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
2) El prólogo XML. Esta línea se llama el prólogo XML :> ?xml version=”1.0” encoding=”UTF-8”?>
> p>This is a paragraph.(/p>
br />
>note date="12/11/2007"> >to>Tove>>/to> >from>Jani>/from> >/note> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ 6) Referencias de entidad: - Algunos caracteres tienen un significado especial en XML.
< < less than > > greater than & & ampersand ' ' apostrophe " " quotation mark
- Solo con & gt; también. \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ 7) Comentarios en XML: - La sintaxis para escribir comentarios en XML es similar a la de HTML: >!-- This is a comment -->
XML: Hello Tove
HTML: Hello Tove
____________________
9) XML almacena una nueva línea como LF:
- Las aplicaciones de Windows almacenan una nueva línea como: retorno de carro y avance de línea (CR + LF).
12- Elementos XML:
Un documento XML contiene elementos XML.
1) ¿Qué es un elemento XML?
- Un elemento XML es todo (desde) la etiqueta de inicio del elemento hasta (incluida) la etiqueta final del elemento.
(price>29.99(/price>
- Un elemento puede contener:
> texto
> atributos
> otros elementos
> o una mezcla de lo anterior
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
2) Ejemplo:
>bookstore>
>xbook category="children">
>title>Harry Potter>/title>
>author>J K. Rowling>/author>
>year>2005>/year>
>price>29.99>/price>
>/book>
>book category="web">
>title>Learning XML>/title>
>author>Erik T. Ray>/author>
>year>2003>/year>
>price>39.95>/price>
>/book>
>/bookstore>En el ejemplo anterior:
13) Reglas de nomenclatura XML:
Los elementos XML deben seguir estas reglas de nomenclatura:
14) Mejores prácticas de nomenclatura:
15) Nomenclatura de estilos:
Estilo/ Ejemplo/ Descripción
1) Minúscula / / Todas las letras minúsculas
2) Mayúscula / / Todas las letras mayúsculas
3) Guion bajo / / El guión bajo separa las palabras
4) Caso Pascal / /Primera letra mayúscula en cada palabra
5) El caso de Carmel / / Primera letra mayúscula en cada palabra excepto la primera
6) Si elige un estilo de nombre, ¡es bueno ser coherente!
- Los documentos XML a menudo tienen una base de datos correspondiente. Una práctica común es usar las reglas de nomenclatura de la base de datos para los elementos XML.
- Camel case es una regla de denominación común en JavaScripts.
16) Los elementos XML son extensibles
>note> >to>Tove(/to> >from>Jani>/from> >body>Don't forget me this weekend!>/body> >/note>
Imaginemos que creamos una aplicación que extrajo los elementos >to>, >from> y >body> del documento XML para producir esta salida:
MENSAJE
Para: Tove
De: Jani
¡No me olvides este fin de semana!
Imagine que el autor del documento XML le agregó información adicional:
>note> >date>2008-01-10>/date> >to>Tove>/to> >from>Jani>/from> >heading>Reminder>/heading> >body>Don't forget me this weekend!>/body> >/note>
¿Debería la aplicación romperse o bloquearse?
No. La aplicación aún debería poder encontrar los elementos , y en el documento XML y producir el mismo resultado.
Esta es una de las bellezas de XML. Se puede ampliar sin romper las aplicaciones.
17) Atributos XML:
> person gender=”female”>
o así:
> person gender=’female’>
> gangster name=’George “Shotgun” Ziegler’>
o puedes usar entidades de caracteres:
>gangster name="George "Shotgun" Ziegler"> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ 2) Elementos XML vs. Atributos - Eche un vistazo a estos ejemplos: >person gender="female"> >firstname>Anna>/firstname> >lastname>Smith>/lastname> >/person>
>person> >gender>female>/gender> >firstname>Anna>/firstname> >lastname>Smith>/lastname> >/person>
18) Mi manera favorita:
> note date=”2008-01-10”>
to>Tove>/to>
from>Jani>/from>
/note>
2) Un elemento se usa en el segundo ejemplo:
>note> >date>2008-01-10>/date> >to>Tove>/to> >from>Jani>/from> >/note>
3) Se utiliza un elemento expandido en el tercer ejemplo: (ESTE ES MI FAVORITO):
>note>
>date>
>year>2008>/year>
>month>01(/month>
>day>10>/day>
>/date>
>to>Tove>/to>
>from>Jani>/from>
>/note>19) ¿Evitar los atributos XML?
> note day=”10” month=”01” year=”2008”
to=”Tove” from=”Jani” heading=”Reminder”
body=”Don’t forget me this weekend!”>
/note>
20) Atributos XML para metadatos:
>messages>
>note id="501">
>to>Tove>/to>
>from>Jani>/from>
>heading>Reminder>/heading>
>body>Don't forget me this weekend!>/body>
>/note>
>note id="502">
>to>Jani>/to>
>from>Tove>/from>
>heading>Re: Reminder>/heading>
>body>I will not>/body>
>/note>
>/messages>21) Espacios de nombres XML:
>table>
>tr>
>td>Apples>/td>
>td>Bananas>/td>
>/tr>
>/table>>table> >name>African Coffee Table>/name> >width>80>/width> >length>120>/length> >/table>
22) Resolver el conflicto de nombres usando un prefijo:
>h:table>
>h:tr>
>h:td>Apples>/h:td>
Bananas>/h:td>
>/h:tr>
>/h:table>>f:table> >f:name>African Coffee Table>/f:name> >f:width>80>/f:width> >f:length>120>/f:length> >/f:table>
23) Espacios de nombres XML: el atributo xmlns
> root>
>h:table xmlns:h="http://www.w3.org/TR/html4/">
>h:tr>
>h:td>Apples>/h:td>
>h:td>Bananas>/h:td>
>/h:tr>
>/h:table>>f:table xmlns:f="https://www.w3schools.com/furniture"> >f:name>African Coffee Table>/f:name> >f:width>80>/f:width> >f:length>120>/f:length> >/f:table>
> /root>
> root xmlns:h=”http://www.w3.org/TR/html4/”
xmlns:f=”https://www.w3schools.com/furniture”>
>h:table>
>h:tr>
>h:td>Apples>/h:td>
>h:td>Bananas>/h:td>
>/h:tr>
>/h:table>>f:table> >f:name>African Coffee Table>/f:name> >f:width>80>/f:width> >f:length>120>/f:length> >/f:table>
> /root>
> Nota: El analizador no utiliza el URI del espacio de nombres para buscar información.
> El propósito de usar un URI es darle al espacio de nombres un nombre único. > Sin embargo, las empresas a menudo usan el espacio de nombres como un puntero a una página web que contiene información del espacio de nombres.
24) Identificador uniforme de recursos (URI)
xmlns=”namespaceURI”
Este XML contiene información de la tabla HTML:
>table xmlns=”http://www.w3.org/TR/html4/”>
>tr>
>td>Apples>/td>
>td>Bananas>/td>
>/tr>
>/table>
Este XML contiene información sobre un mueble:
>table xmlns=”https://www.w3schools.com/furniture”>
>name>African Coffee Table>/name>
>width>80(/width>
>length>120>/length>
>/table>
____________________
2) Espacios de nombres en uso real
- XSLT es un lenguaje que se puede usar para transformar documentos XML en otros formatos.
> ?xml version=”1.0” encoding=”UTF-8”?>
> xsl:stylesheet version=”1.0” xmlns:xsl=”http://www.w3.org/1999/XSL/Transform”>
>xsl:template match="/">
>html>
>body>
>h2>My CD Collection>/h2>
>table border="1">
>tr>
>th style="text-align:left">Title>/th>
>th style="text-align:left">Artist>/th>
>/tr>
>xsl:for-each select="catalog/cd">
>tr>
>td>(xsl:value-of select="title"/>>/td>
>td>(xsl:value-of select="artist"/>>/td>
>/tr>
>/xsl:for-each>
>/table>
>/body>
>/html>
>/xsl:template>> /xsl:stylesheet>