Вы находитесь на странице: 1из 4

Ejemplo 1:

<?xml version="1.0" encoding="UTF-8"?>


<Librera xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Libreria.xsd">
<Libro>
<Ttulo>Libro1</Ttulo>
<Autor>Autor1</Autor>
<Fecha>10 de mayo de 2015</Fecha>
<ISBN>33445</ISBN>
<Editorial>Editorial1</Editorial>
</Libro>
<Libro>
<Ttulo>Libro2</Ttulo>
<Autor>autor2</Autor>
<Fecha>15 de mayo de 2015</Fecha>
<ISBN>33556</ISBN>
<Editorial>Editorial2</Editorial>
</Libro>
</Librera>

Su DTD, que identificamos por libreria.dtd ser:

Su correspondiente sintaxis como esquema sera libreria.xsd:

<?xml version="1.0" encoding="UTF-8"?>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Librera">
<xs:complexType>
<xs:sequence>
<xs:element name="Libro" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Ttulo" type="xs:string"/>
<xs:element name="Autor" type="xs:string"/>
<xs:element name="Fecha" type="xs:string"/>
<xs:element name="ISBN" type="xs:string"/>
<xs:element name="Editorial" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

o
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Librera">
<xs:complexType>
<xs:sequence>
<xs:element ref="Libro" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Libro">
<xs:complexType>
<xs:sequence>
<xs:element ref="Ttulo"/>
<xs:element ref="Autor"/>
<xs:element ref="Fecha"/>
<xs:element ref="ISBN"/>
<xs:element ref="Editorial"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Ttulo" type="xs:string"/>
<xs:element name="Editorial" type="xs:string"/>
<xs:element name="ISBN" type="xs:string"/>
<xs:element name="Autor" type="xs:string"/>
<xs:element name="Fecha" type="xs:string"/>
</xs:schema>

Ejemplo 2:

Documento XML:Atlas.xml

<?xml version="1.0" encoding="UTF-8"?>


<Atlas xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="Atlas.xsd">
<Pais>
<Nombre>Colombia</Nombre>
<Capital>Bogot</Capital>
<Poblacin>450000000</Poblacin>
<Extensin>1141748</Extensin>
</Pais>
<Pais>
<Nombre>Espaa</Nombre>
<Capital>Madrid</Capital>
<Poblacin>416000000</Poblacin>
<Extensin>505957</Extensin>
</Pais>
</Atlas>

Y el resultado de generalizar Atlas.xml a un esquema XML ser Atlas.xsd:

<?xml version="1.0" encoding="UTF-8"?>


<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Atlas">
<xs:complexType>
<xs:sequence>
<xs:element ref="Pais" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Pais">
<xs:complexType>
<xs:sequence>
<xs:element ref="Nombre"/>
<xs:element ref="Capital"/>
<xs:element ref="Poblacin"/>
<xs:element ref="Extensin" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Nombre" type="xs:string"/>
<xs:element name="Capital" type="xs:string"/>
<xs:element name="Poblacin" type="xs:string"/>
<xs:element name="Extensin" type="xs:string"/>
</xs:schema>

La DTD correspondiente a este documento es :

<!ELEMENT Atlas(Pais+)>
<!ELEMENT Pais(Nombre,Capital,Poblacin,Extensin)>
<!ELEMENT Nombre (#PCDATA)>
<!ELEMENT Capital (#PCDATA)>
<!ELEMENT Poblacin (#PCDATA)>
<!ELEMENT Extensin (#PCDATA)>

Вам также может понравиться