SlideShare une entreprise Scribd logo
1  sur  27
XML Schema Carlos Castillo [email_address] Departamento de Ciencias de la Computacion Facultad de Ciencias Fisicas y Matematicas Universidad de Chile
“Data-oriented” XML ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],factura.xml
“Document-oriented” XML ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],memo.xml
Propósito lenguaje schema ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Requerimientos Schema ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Jerarquía de lenguajes
Características XML Schema ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Ejemplo simple XML Schema <?xml version=&quot;1.0&quot;?> <xsd: schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;http://www.example.com&quot; targetNamespace=&quot;http://www.example.com&quot; elementFormDefault=&quot;qualified&quot;> <xsd: element   name =&quot;note&quot;> <xsd: complexType > <xsd: sequence > <xsd:element name=&quot;to&quot;  type =&quot;xsd:string&quot;/> <xsd:element name=&quot;from&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;heading&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;body&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>  note.xsd
Ejemplo simple XML Schema + doc. <xsd:element name=&quot;note&quot;> <xsd:complexType> <xsd:sequence> <xsd:element name=&quot;to&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;from&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;heading&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;body&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:element note.xsd <?xml version=”1.0”?> <note> < to >Juan</ to > < from >Miguel</ from > < heading >Llama a X</ heading > < body >X te busca urgente</ body > </note> note.xml
XML Schema v/s DTD, 1/2 <xsd:element name=&quot;note&quot;> <xsd:complexType> <xsd:sequence> <xsd:element name=&quot;to&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;from&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;heading&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;body&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:element note.xsd <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> note.dtd
XML Schema v/s DTD, 2/2 <xsd:element name=&quot;note&quot;> <xsd:complexType> <xsd:sequence> <xsd:element name=&quot;to&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;priority&quot; type=&quot; xsd:integer &quot;/> <xsd:element name=&quot;heading&quot;> <xsd:simpleType> <xsd:restriction base=&quot;xsd:string&quot;> <xsd:maxLength value=&quot;10&quot;/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name=&quot;body&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:element> note2.xsd <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT priority ( #PCDATA )> <!ELEMENT heading ( #PCDATA )> <!ELEMENT body (#PCDATA)> note2.dtd
Orden de compra <?xml version=&quot;1.0&quot;?> <purchaseOrder orderDate=&quot;1999-10-20&quot;> <shipTo country=&quot;US&quot;> <name>Alice Smith</name> <street>12 Maple Street</street> <city>Mill Valley</city> <state>CA</state> <zip>90952</zip> </shipTo> <billTo country=&quot;US&quot;> <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=&quot;872-AA&quot;> < productName >Lawnmower</productName> <quantity>1</quantity> <USPrice>148.95</USPrice> <comment>Confirm this is electric</comment> </item> <item partNum=&quot;926-AA&quot;> <productName>Baby Monitor</productName> <quantity>1</quantity> <USPrice>39.98</USPrice> <shipDate>1999-05-21</shipDate> </item> </items> </purchaseOrder> orden_compra.xml
Orden de compra (tipos dato) <?xml version=&quot;1.0&quot;?> <purchaseOrder orderDate=&quot; 1999-10-20 &quot;> <shipTo country=&quot; US &quot;> <name>Alice Smith</name> <street>12 Maple Street</street> <city>Mill Valley</city> <state> CA </state> <zip> 90952 </zip> </shipTo> <billTo country=&quot;US&quot;> <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=&quot; 872-AA &quot;> < productName >Lawn mower</productName> <quantity> 2 </quantity> <USPrice> 148.95 </USPrice> <comment>Confirm this is electric</comment> </item> <item partNum=&quot;926-AA&quot;> <productName>Baby Monitor</productName> <quantity>1</quantity> <USPrice>39.98</USPrice> <shipDate>1999-05-21</shipDate> </item> </items> </purchaseOrder> orden_compra.xml
XML Schema 1/3 <schema xmlns=&quot; http://www.w3.org/2001/XMLSchema &quot;> <annotation> <documentation xml:lang=&quot;en&quot;> Purchase order schema for Example.com. Copyright 2000 Example.com. All rights reserved. </documentation> </annotation> <element name=&quot;purchaseOrder&quot; type=&quot;PurchaseOrderType&quot;/> <!-- Tipo complejo --> <complexType name=&quot;PurchaseOrderType&quot;> <sequence> <element name=&quot;shipTo&quot; type=&quot;USAddress&quot;/> <element name=&quot;billTo&quot; type=&quot;USAddress&quot;/> <element ref=&quot;comment&quot; minOccurs=&quot;0&quot;/> <element name=&quot;items&quot;  type=&quot;Items&quot;/> </sequence> <attribute name=&quot;orderDate&quot; type=&quot;date&quot;/> </complexType>
XML Schema 2/3 <!-- Tipo complejo --> <complexType name=&quot;USAddress&quot;> <sequence> <element name=&quot;name&quot;  type=&quot;string&quot;/> <element name=&quot;street&quot; type=&quot;string&quot;/> <element name=&quot;city&quot;  type=&quot;string&quot;/> <element name=&quot;state&quot;  type=&quot;string&quot;/> <element name=&quot;zip&quot;  type=&quot;decimal&quot;/> </sequence> <attribute name=&quot;country&quot; type=&quot;NMTOKEN&quot; fixed=&quot;US&quot;/> </complexType> <!-- Tipo simple --> <simpleType name=&quot;SKU&quot;> <restriction base=&quot;string&quot;> <pattern value=&quot;{3}-[A-Z]{2}&quot;/> </restriction> </simpleType> <!-- Elemento --> <element name=&quot;comment&quot; type=&quot;string&quot;/>
XML Schema Ej (3) <complexType name=&quot;Items&quot;> <sequence> <element name=&quot;item&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;> <complexType> <sequence> <element name=&quot;productName&quot; type=&quot;string&quot;/> <element name=&quot;quantity&quot;> <simpleType> <restriction base=&quot;positiveInteger&quot;> <maxExclusive value=&quot;100&quot;/> </restriction> </simpleType> </element> <element name=&quot;USPrice&quot;  type=&quot;decimal&quot;/> <element ref=&quot;comment&quot;  minOccurs=&quot;0&quot;/> <element name=&quot;shipDate&quot; type=&quot;date&quot; minOccurs=&quot;0&quot;/> </sequence> <attribute name=&quot;partNum&quot; type=&quot;SKU&quot; use=&quot;required&quot;/> </complexType> </element> </sequence> </complexType> </schema>
Tipos de tipos de dato ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Derivacion de tipos ,[object Object],[object Object],[object Object],[object Object],[object Object]
Elemento, Compuesto, Attr ,[object Object],[object Object],<complexType name=&quot;USAddress&quot;> <sequence> <element name=&quot;name&quot;  type=&quot;string&quot;/> <element name=&quot;street&quot; type=&quot;string&quot;/> <element name=&quot;city&quot;  type=&quot;string&quot;/> <element name=&quot;state&quot;  type=&quot;string&quot;/> <element name=&quot;zip&quot;  type=&quot;decimal&quot;/> </sequence> <attribute name=&quot;country&quot; type=&quot;NMTOKEN&quot; fixed=&quot;US&quot;/> </complexType>
Restricciones multiplicidad ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],<element ref=&quot;comment&quot; minOccurs=&quot;0&quot;/>
Tipos simples ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nuevos tipos simples <simpleType name=”myInteger”> <restriction base=”integer”> <minInclusive value=”10000”/> <maxInclusive value=”99999”/> </restriction> </simpleType> ,[object Object],[object Object]
Nuevos tipos enumerados <simpleType name=”deptosIngenieria”> <restriction base=”string”> <enumeration value=”cc”/> <enumeration value=”ci”/> <enumeration value=”eh”/> <enumeration value=”ma”/> ... <enumeration value=”in”/> </restriction> </simpleType> ,[object Object]
Tipo lista <simpleType name=”listDeptos”> <list itemType=”deptosIngenieria”/> </simpleType> <!-- Ejemplo --> <listado>in ma cc</listado> ,[object Object]
Contenido mixed ,[object Object],<element name=”body”> <complexType mixed=”true”> <element name=”b”/> </complexType> </element>
 
Otras características ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Contenu connexe

Plus de Carlos Castillo (ChaTo)

Finding High Quality Content in Social Media
Finding High Quality Content in Social MediaFinding High Quality Content in Social Media
Finding High Quality Content in Social MediaCarlos Castillo (ChaTo)
 
Socia Media and Digital Volunteering in Disaster Management @ DSEM 2017
Socia Media and Digital Volunteering in Disaster Management @ DSEM 2017Socia Media and Digital Volunteering in Disaster Management @ DSEM 2017
Socia Media and Digital Volunteering in Disaster Management @ DSEM 2017Carlos Castillo (ChaTo)
 
Detecting Algorithmic Bias (keynote at DIR 2016)
Detecting Algorithmic Bias (keynote at DIR 2016)Detecting Algorithmic Bias (keynote at DIR 2016)
Detecting Algorithmic Bias (keynote at DIR 2016)Carlos Castillo (ChaTo)
 

Plus de Carlos Castillo (ChaTo) (20)

Finding High Quality Content in Social Media
Finding High Quality Content in Social MediaFinding High Quality Content in Social Media
Finding High Quality Content in Social Media
 
When no clicks are good news
When no clicks are good newsWhen no clicks are good news
When no clicks are good news
 
Socia Media and Digital Volunteering in Disaster Management @ DSEM 2017
Socia Media and Digital Volunteering in Disaster Management @ DSEM 2017Socia Media and Digital Volunteering in Disaster Management @ DSEM 2017
Socia Media and Digital Volunteering in Disaster Management @ DSEM 2017
 
Detecting Algorithmic Bias (keynote at DIR 2016)
Detecting Algorithmic Bias (keynote at DIR 2016)Detecting Algorithmic Bias (keynote at DIR 2016)
Detecting Algorithmic Bias (keynote at DIR 2016)
 
Discrimination Discovery
Discrimination DiscoveryDiscrimination Discovery
Discrimination Discovery
 
Fairness-Aware Data Mining
Fairness-Aware Data MiningFairness-Aware Data Mining
Fairness-Aware Data Mining
 
Big Crisis Data for ISPC
Big Crisis Data for ISPCBig Crisis Data for ISPC
Big Crisis Data for ISPC
 
Databeers: Big Crisis Data
Databeers: Big Crisis DataDatabeers: Big Crisis Data
Databeers: Big Crisis Data
 
Observational studies in social media
Observational studies in social mediaObservational studies in social media
Observational studies in social media
 
Natural experiments
Natural experimentsNatural experiments
Natural experiments
 
Content-based link prediction
Content-based link predictionContent-based link prediction
Content-based link prediction
 
Link prediction
Link predictionLink prediction
Link prediction
 
Recommender Systems
Recommender SystemsRecommender Systems
Recommender Systems
 
Graph Partitioning and Spectral Methods
Graph Partitioning and Spectral MethodsGraph Partitioning and Spectral Methods
Graph Partitioning and Spectral Methods
 
Finding Dense Subgraphs
Finding Dense SubgraphsFinding Dense Subgraphs
Finding Dense Subgraphs
 
Graph Evolution Models
Graph Evolution ModelsGraph Evolution Models
Graph Evolution Models
 
Link-Based Ranking
Link-Based RankingLink-Based Ranking
Link-Based Ranking
 
Text Indexing / Inverted Indices
Text Indexing / Inverted IndicesText Indexing / Inverted Indices
Text Indexing / Inverted Indices
 
Indexing
IndexingIndexing
Indexing
 
Text Summarization
Text SummarizationText Summarization
Text Summarization
 

XML Schema

  • 1. XML Schema Carlos Castillo [email_address] Departamento de Ciencias de la Computacion Facultad de Ciencias Fisicas y Matematicas Universidad de Chile
  • 2.
  • 3.
  • 4.
  • 5.
  • 7.
  • 8. Ejemplo simple XML Schema <?xml version=&quot;1.0&quot;?> <xsd: schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot; xmlns=&quot;http://www.example.com&quot; targetNamespace=&quot;http://www.example.com&quot; elementFormDefault=&quot;qualified&quot;> <xsd: element name =&quot;note&quot;> <xsd: complexType > <xsd: sequence > <xsd:element name=&quot;to&quot; type =&quot;xsd:string&quot;/> <xsd:element name=&quot;from&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;heading&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;body&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> note.xsd
  • 9. Ejemplo simple XML Schema + doc. <xsd:element name=&quot;note&quot;> <xsd:complexType> <xsd:sequence> <xsd:element name=&quot;to&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;from&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;heading&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;body&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:element note.xsd <?xml version=”1.0”?> <note> < to >Juan</ to > < from >Miguel</ from > < heading >Llama a X</ heading > < body >X te busca urgente</ body > </note> note.xml
  • 10. XML Schema v/s DTD, 1/2 <xsd:element name=&quot;note&quot;> <xsd:complexType> <xsd:sequence> <xsd:element name=&quot;to&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;from&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;heading&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;body&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:element note.xsd <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT heading (#PCDATA)> <!ELEMENT body (#PCDATA)> note.dtd
  • 11. XML Schema v/s DTD, 2/2 <xsd:element name=&quot;note&quot;> <xsd:complexType> <xsd:sequence> <xsd:element name=&quot;to&quot; type=&quot;xsd:string&quot;/> <xsd:element name=&quot;priority&quot; type=&quot; xsd:integer &quot;/> <xsd:element name=&quot;heading&quot;> <xsd:simpleType> <xsd:restriction base=&quot;xsd:string&quot;> <xsd:maxLength value=&quot;10&quot;/> </xsd:restriction> </xsd:simpleType> </xsd:element> <xsd:element name=&quot;body&quot; type=&quot;xsd:string&quot;/> </xsd:sequence> </xsd:complexType> </xsd:element> note2.xsd <!ELEMENT note (to,from,heading,body)> <!ELEMENT to (#PCDATA)> <!ELEMENT priority ( #PCDATA )> <!ELEMENT heading ( #PCDATA )> <!ELEMENT body (#PCDATA)> note2.dtd
  • 12. Orden de compra <?xml version=&quot;1.0&quot;?> <purchaseOrder orderDate=&quot;1999-10-20&quot;> <shipTo country=&quot;US&quot;> <name>Alice Smith</name> <street>12 Maple Street</street> <city>Mill Valley</city> <state>CA</state> <zip>90952</zip> </shipTo> <billTo country=&quot;US&quot;> <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=&quot;872-AA&quot;> < productName >Lawnmower</productName> <quantity>1</quantity> <USPrice>148.95</USPrice> <comment>Confirm this is electric</comment> </item> <item partNum=&quot;926-AA&quot;> <productName>Baby Monitor</productName> <quantity>1</quantity> <USPrice>39.98</USPrice> <shipDate>1999-05-21</shipDate> </item> </items> </purchaseOrder> orden_compra.xml
  • 13. Orden de compra (tipos dato) <?xml version=&quot;1.0&quot;?> <purchaseOrder orderDate=&quot; 1999-10-20 &quot;> <shipTo country=&quot; US &quot;> <name>Alice Smith</name> <street>12 Maple Street</street> <city>Mill Valley</city> <state> CA </state> <zip> 90952 </zip> </shipTo> <billTo country=&quot;US&quot;> <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=&quot; 872-AA &quot;> < productName >Lawn mower</productName> <quantity> 2 </quantity> <USPrice> 148.95 </USPrice> <comment>Confirm this is electric</comment> </item> <item partNum=&quot;926-AA&quot;> <productName>Baby Monitor</productName> <quantity>1</quantity> <USPrice>39.98</USPrice> <shipDate>1999-05-21</shipDate> </item> </items> </purchaseOrder> orden_compra.xml
  • 14. XML Schema 1/3 <schema xmlns=&quot; http://www.w3.org/2001/XMLSchema &quot;> <annotation> <documentation xml:lang=&quot;en&quot;> Purchase order schema for Example.com. Copyright 2000 Example.com. All rights reserved. </documentation> </annotation> <element name=&quot;purchaseOrder&quot; type=&quot;PurchaseOrderType&quot;/> <!-- Tipo complejo --> <complexType name=&quot;PurchaseOrderType&quot;> <sequence> <element name=&quot;shipTo&quot; type=&quot;USAddress&quot;/> <element name=&quot;billTo&quot; type=&quot;USAddress&quot;/> <element ref=&quot;comment&quot; minOccurs=&quot;0&quot;/> <element name=&quot;items&quot; type=&quot;Items&quot;/> </sequence> <attribute name=&quot;orderDate&quot; type=&quot;date&quot;/> </complexType>
  • 15. XML Schema 2/3 <!-- Tipo complejo --> <complexType name=&quot;USAddress&quot;> <sequence> <element name=&quot;name&quot; type=&quot;string&quot;/> <element name=&quot;street&quot; type=&quot;string&quot;/> <element name=&quot;city&quot; type=&quot;string&quot;/> <element name=&quot;state&quot; type=&quot;string&quot;/> <element name=&quot;zip&quot; type=&quot;decimal&quot;/> </sequence> <attribute name=&quot;country&quot; type=&quot;NMTOKEN&quot; fixed=&quot;US&quot;/> </complexType> <!-- Tipo simple --> <simpleType name=&quot;SKU&quot;> <restriction base=&quot;string&quot;> <pattern value=&quot;{3}-[A-Z]{2}&quot;/> </restriction> </simpleType> <!-- Elemento --> <element name=&quot;comment&quot; type=&quot;string&quot;/>
  • 16. XML Schema Ej (3) <complexType name=&quot;Items&quot;> <sequence> <element name=&quot;item&quot; minOccurs=&quot;0&quot; maxOccurs=&quot;unbounded&quot;> <complexType> <sequence> <element name=&quot;productName&quot; type=&quot;string&quot;/> <element name=&quot;quantity&quot;> <simpleType> <restriction base=&quot;positiveInteger&quot;> <maxExclusive value=&quot;100&quot;/> </restriction> </simpleType> </element> <element name=&quot;USPrice&quot; type=&quot;decimal&quot;/> <element ref=&quot;comment&quot; minOccurs=&quot;0&quot;/> <element name=&quot;shipDate&quot; type=&quot;date&quot; minOccurs=&quot;0&quot;/> </sequence> <attribute name=&quot;partNum&quot; type=&quot;SKU&quot; use=&quot;required&quot;/> </complexType> </element> </sequence> </complexType> </schema>
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.  
  • 27.