Riporto un esempio pratico di trduzione di un DTD di XML nella corrispondente struttura XML
<!-- Descrizione di Eating Source (file Eating_source.dtd) --> <!ELEMENT Eating_Source (Fast-Food)*>
<!-- Dettaglio per Fast-Food --> <!ELEMENT Fast-Food (name,address,phone?,speciality*,category, nearby?,midprice?,owner?)*> <!ELEMENT name (#PCDATA)> <!ATTLIST name id ID #REQUIRED> <!ELEMENT phone (#PCDATA)> <!ELEMENT speciality (#PCDATA)> <!ELEMENT category (#PCDATA)> <!ELEMENT midprice (#PCDATA)>
<!-- Dettaglio per Address --> <!ELEMENT address (#PCDATA|address_type)*> <!ELEMENT address_type (city,street,zipcode)> <!ELEMENT city (#PCDATA)> <!ELEMENT street (#PCDATA)> <!ELEMENT zipcode (#PCDATA)>
<!-- Dettaglio per nearby (Restaurant) --> <!ELEMENT nearby (name_rist,category,street,zip_code,person, tourist_menu_price,special_dish)> <!ELEMENT name_rist (#PCDATA)> <!ATTLIST name_rist r_code ID #REQUIRED> <!ELEMENT zip_code (#PCDATA)> <!ELEMENT person EMPTY> <!ATTLIST person pers_id IDREF #IMPLIED> <!ELEMENT tourist_menu_price (#PCDATA)> <!ELEMENT special_dish (#PCDATA)>
<!-- Dettaglio per owner --> <!ELEMENT owner (name,address,job)> <!ELEMENT job (#PCDATA)>
L'output della funzione getDescriptione produrrebbe (commenti esclusi):
// Da testare la correttezza in ODLi3
//Descrizione dell'interfaccia principale
interface Eating_Source
(source semistructured Eating_Source)
{
attribute set<Fast-Food> Fast-Food;
}
interface Fast-Food
(source semistructured Eating_Source
key name_id
foreign key (owner) references owner)
{
attribute string name;
attribute string name_id;
attribute address address;
attribute string phone*;
attribute set<string> speciality;
attribute string category;
attribute nearby nearby*;
attribute owner owner*;
}
In questo caso è stato considerato che il progettista abbia accettato che l'attribute name_id si tratti di una primary key e come tale è stata tradotto in ODLi3
// Descrizione del tipo owner che descrive una persona
interface owner
(source semistructured Eating_Source
key name_id)
{
attribute string name;
attribute string name_id;
attribute address address;
attribute string job;
}
// Descrizione del tipo address
interface address
(source semistructured Eating_Source)
{
attribute string city;
attribute string street;
attribute string zipcode;
}
union
{
string;
}
// Descrizione del tipo nearby
interface address_type
(source semistructured Eating_Source
key name_rist_r_code)
{
attribute string name_rist;
attribute string name_rist_r_code;
attribute string category;
attribute string street;
attribute string zip_code;
attribute string person_pers_id
attribute string tourist_menu_price;
attribute string special_dish;
}
Un esempio di dati che utilizzano questo DTD può essere dato dal file Eating_Source.xml
The MOMIS Home Page