Curso: Recuperación de Información – 2002/1 XML Schemas Referencias: www.w3.org/XML/Schema www.xfront.com/xml-schemas Curso: Recuperación de Información – 2002/1 -- ChaTo
Data oriented <invoice> <orderDate>1999-01-21</orderDate> <shipDate>1999-01-25</shipDate> <billingAddress> <name>Ashok Malhotra</name> <street>123 Microsoft Ave.</street> <city>Hawthorne</city> <state>NY</state> <zip>10532-0000</zip> </billingAddress> <voice>555-1234</voice> <fax>555-4321</fax> </invoice>
Document oriented <memo importance='high' date='1999-03-23'> <from>Paul V. Biron</from> <to>Ashok Malhotra</to> <subject>Latest draft</subject> <body> We need to discuss the latest draft <emph>immediately</emph>. Either email me at <email> mailto:paul.v.biron@kp.org</email> or call <phone>555-9876</phone> </body> </memo>
Propósito lenguaje schema Describir estructura Anidación Multiplicidad Ordenamiento Describir tipos Para velocidad operatoria Para mejor almacenamiento Para busquedas Para ingreso de datos
Requerimientos Schema Fácil de usar Expresivo Orientado a estructura (DTD) v/s restricciones (Schematron) Poder como mínimo emular razgos de las bases de datos relacionales Llaves primarias Llaves secundarias Tipos nativos de las BD relacionales
Jerarquía de lenguajes Schematron + restricciones + unicidad RELAX + tipos + contexto DTD soporte básico para estructura DSD + restricciones + estructura + version SOX + herencia + tipos XML Schema + restricciones + unicidad + tipos de dato
Características XML Schema Sintaxis en XML Espacios de nombres, includes 45 tipos nativos Tipos de usuario, Tipos complejos Secuencias, Multiplicidad Llaves primarias, unicidad Llaves secundarias
<comment>Hurry, my lawn is going wild!</comment> Orden de compra <?xml version="1.0"?> <purchaseOrder orderDate="1999-10-20"> <shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street> <city>Mill Valley</city> <state>CA</state> <zip>90952</zip> </shipTo> <billTo country="US"> <name>Robert Smith</name> <street>8 Oak Avenue</street> <city>Old Town</city> <state>PA</state> <zip>95819</zip> </billTo> <comment>Hurry, my lawn is going wild!</comment> <items> <item partNum="872-AA"> <productName>Lawnmower</productName> <quantity>1</quantity> <USPrice>148.95</USPrice> <comment>Confirm this is electric</comment> </item> <item partNum="926-AA"> <productName>Baby Monitor</productName> <USPrice>39.98</USPrice> <shipDate>1999-05-21</shipDate> </items> </purchaseOrder>
Orden de compra (gramáticas) <?xml version="1.0"?> <purchaseOrder orderDate="1999-10-20"> <shipTo country="US"> <name>Alice Smith</name> <street>123 Maple Street</street> <city>Mill Valley</city> <state>CA</state> <zip>90952</zip> </shipTo> <billTo country="US"> <name>Robert Smith</name> <street>8 Oak Avenue</street> <city>Old Town</city> <state>PA</state> <zip>95819</zip> </billTo> <comment>Hurry, my lawn is going wild!</comment> <items> <item partNum="872-AA"> <productName>Lawnmower</productName> <quantity>1</quantity> <USPrice>148.95</USPrice> <comment>Confirm this is electric</comment> </item> <item partNum="926-AA"> <productName>Baby Monitor</productName> <USPrice>39.98</USPrice> <shipDate>1999-05-21</shipDate> </items> </purchaseOrder>
XML Schema Ej (1) <schema xmlns="http://www.w3.org/2001/XMLSchema"> <annotation> <documentation xml:lang="en"> Purchase order schema for Example.com. Copyright 2000 Example.com. All rights reserved. </documentation> </annotation> <element name="purchaseOrder" type="PurchaseOrderType"/> <!-- Tipo complejo --> <complexType name="PurchaseOrderType"> <sequence> <element name="shipTo" type="USAddress"/> <element name="billTo" type="USAddress"/> <element ref="comment" minOccurs="0"/> <element name="items" type="Items"/> </sequence> <attribute name="orderDate" type="date"/> </complexType>
XML Schema Ej (2) <!-- Tipo simple --> <!-- Tipo complejo --> <complexType name="USAddress"> <sequence> <element name="name" type="string"/> <element name="street" type="string"/> <element name="city" type="string"/> <element name="state" type="string"/> <element name="zip" type="decimal"/> </sequence> <attribute name="country" type="NMTOKEN" fixed="US"/> </complexType> <!-- Tipo simple --> <simpleType name="SKU"> <restriction base="string"> <pattern value="\d{3}-[A-Z]{2}"/> </restriction> </simpleType> <!-- Elemento --> <element name="comment" type="string"/>
XML Schema Ej (3) <complexType name="Items"> <sequence> <element name="item" minOccurs="0" maxOccurs="unbounded"> <complexType> <element name="productName" type="string"/> <element name="quantity"> <simpleType> <restriction base="positiveInteger"> <maxExclusive value="100"/> </restriction> </simpleType> </element> <element name="USPrice" type="decimal"/> <element ref="comment" minOccurs="0"/> <element name="shipDate" type="date" minOccurs="0"/> </sequence> <attribute name="partNum" type="SKU" use="required"/> </complexType> </schema>
Editor XMLSpy
Tipos de tipos de dato Singulares Listas Uniones Primitivos Derivados Dependientes de un solo tipo Uniones Listas heterogeneas (varios tipos)
Derivacion de tipos Por restriccion Por listado Por union Tipico: string restringido a una regexp Por listado Por union 'Tipos complejos'
Elemento, Compuesto, Attr Tipo complejo = compuesto tipos simples ComplexType contiene elementos y atributos <complexType name="USAddress"> <sequence> <element name="name" type="string"/> <element name="street" type="string"/> <element name="city" type="string"/> <element name="state" type="string"/> <element name="zip" type="decimal"/> </sequence> <attribute name="country" type="NMTOKEN" fixed="US"/> </complexType>
Restricciones multiplicidad <element ref="comment" minOccurs="0"/> Comment es opcional minOccurs default 1 maxOccurs default 1 (“unbounded) Atributos use = (required, optional, prohibited) Valores fijos y default fixed = “...” default = “...”
Tipos simples string byte, unsignedByte (-1,126;0,255) base64Binary (GpM7) hexBinary (FF00EE) integer, positiveInteger, negativeInteger int, long, short, float, double, boolean time, duration Qname, anyURI
Nuevos tipos simples Se definen como restricciones en base a otros tipos de dato simples <simpleType name=”myInteger”> <restriction base=”integer”> <minInclusive value=”10000”/> <maxInclusive value=”99999”/> </restriction> </simpleType> Pueden ser anónimos (ej.: quantity)
Nuevos tipos enumerados Se definen por extensión <simpleType name=”deptosIngenieria”> <restriction base=”string”> <enumeration value=”cc”/> <enumeration value=”ci”/> <enumeration value=”eh”/> <enumeration value=”ma”/> ... <enumeration value=”in”/> </restriction> </simpleType>
Tipo lista Soporte nativo para listas en elementos <simpleType name=”listDeptos”> <list itemType=”deptosIngenieria”/> </simpleType> <!-- Ejemplo --> <listado>in ma cc</listado>
Contenido mixed Mixed en este mundo significa texto plano y elementos <element name=”body”> <complexType mixed=”true”> <element name=”b”/> </complexType> </element>
Otras características Soporte para anotaciones Extensiones a sequence Choice Grupos de atributos compartidos Espacios de nombres Tipos globales, locales, scope de archivo Tipos abstractos no pueden tener instancias, sólo subtipos