L’eXtensible Markup Language, fin dalla sua nascita, ha avuto un gran consenso da parte di tutti gli attori che operano nel mondo informatico, diventando di fatto la base di molte applicazioni, in particolar modo di quelle che fondano la loro attività sullo scambio di informazioni, per la sua semplicità ed interoperabilità.
2. L’eXtensible Markup Language, fin dalla sua
nascita, ha avuto un gran consenso da parte di
tutti gli attori che operano nel mondo
informatico, diventando di fatto la base di
molte applicazioni, in particolar modo di quelle
che fondano la loro attività sullo scambio di
informazioni, per la sua semplicità ed
interoperabilità.
Eidon School 2
3. Agenda
XML e Namespace
Accenni di
XMLSchema
XSL
XPath
XSL-Fo
Eidon School 3
5. Le origini di XML 1/2
L’XML è un metalinguaggio, derivato da SGML
(Standard Generalized Markup Language standard
internazionale ISO 8879 del 1986) che ha il compito di
rappresentare informazioni strutturate più rigidamente
rispetto al suo predecessore. L’SGML deriva dal GML,
creato da IBM nel ’69, che aveva come obiettivo quello di
rendere i documenti elettronici più comprensibili e
versatili, indipendenti dal mezzo di consultazione e di
sollevare l’autore dal compito di impaginazione (per
qualunque output, carta, pagina web, presentazione,
ecc.)...e per durare per tempo!
Eidon School 5
6. Le origini di XML 2/2
L’SGML non ha avuto notorietà essendo complicato da
implementare.
L’HTML, un altro derivato di SGML, ha avuto invece un
successo enorme per la sua semplicità e per il boom dei
web browser.
L’XML è un metalinguaggio che mira a migliorare sia
l’SGML perché complesso, sia l’HTML (perché mischia
nel testo informazioni di impaginazione e formattazione).
È stato formalizzato dal W3C nel febbraio ’98,
attualmente (2009) la versione 1.1 è W3C
recommendation.
Eidon School 6
7. Ma cos’è XML?
È una raccomandazione del W3C
http://www.w3.org/XML
Consiste in un insieme di tag (marcatori di testo che
sono racchiusi da “<“ e “>”) e attributi definiti
dall’utente che permettono di rappresentare
un’informazione in maniera gerarchica.
È uno standard aperto libero da royalty, brevetti,
copyright o segreti industriali.
Auto esplicativo.
Creabile ed editabile con un semplice editor di testo.
Eidon School 7
8. ..e cosa non è!
Un linguaggio di programmazione.
Un sostituto di HTML.
Un protocollo di comunicazione.
Uno standard binario.
Eidon School 8
9. Vediamo un esempio di XML
<?xml version="1.1" encoding=”UTF-8”?>
<computer>
<!—questo è un commento-->
<memoria tipo=”DDR” unit=”Mb”>512</memoria>
<CPU>1.2 GHz</CPU>
<tastiera>400 tasti</tastiera>
<HD>
<HardDisk>7200 rpm 5Gb</HardDisk>
<HardDisk>7200 rpm 224Tb</HardDisk>
</HD>
<descrizione><![CDATA[ questo è
un ottimo <<PC>>!]]>
</descrizione>
<lettore/>
</computer>
Eidon School 9
10. Esaminiamolo!
Questa è una fantomatica descrizione di un computer.
Un documento XML è formato da due parti:
Un prologo facoltativo (ma raccomandato per
indicare la versione del documento xml e la
codifica) che vedremo tra pochissimo
Il corpo del documento
Eidon School 10
11. Processing Instructions
Sono delle direttive che forniscono informazioni su
come leggere/parserizzare i file xml.
Sono racchiusi tra “<?” e “?>”.
Come per i commenti, possono trovarsi in
qualunque punto del documento ma non dentro un
tag es. <tag NO-QUI>.
<?robots index="yes" follow="no"?>
<?xml-stylesheet href="person.css" type="text/css"?>
<?php mysql_connect("database.unc.edu", "debra",
"secret"); ?>
Eidon School 11
12. Il prologo (XML Declaration)
È una process instruction riservata
Se c’è, deve trovarsi in testa al documento
Nell’esempio che abbiamo visto era:
<?xml version="1.1" encoding=”UTF-8”?>
Il primo indica la versione di XML utilizzata, la più recente è la
1.1. Il secondo l’encoding del documento (in questo caso UTF-
8, che è anche il charterset di default per XML).
È possibile indicare anche standalone="yes"
Xml, XML, xml ecc. in qualunque combinazione di case sono
riservati.
Eidon School 12
13. Il corpo
Dopo il possibile prologo, segue una radice da cui si
origina l’albero del documento. Come l’esempio
dimostra, la radice dell’elemento contiene i dati (le
informazioni vere e proprie) tra i marcatori mentre
quest’ultimi si occupano di definire la struttura
gerarchica del documento.
Eidon School 13
14. Strutturare al meglio!
Vediamo che le informazioni, i dati veri e propri, del documento
sono contenuti dentro dei tag all’interno dei quali è possibile
inserire anche altri tag figli.
Benché sia ammissibile avere tag figli e testo dentro lo stesso
marcatore (“tag a contenuto misto”), ad esempio:
<HD>
Haqdrdisk
<HardQ>5</ HardQ>
</HD>
è sconsigliato, in quanto si complica la creazione di documenti
che controllano la correttezza del nostro XML
Eidon School 14
15. Attributi
I nostri elementi possono contenere anche attributi come questi:
<memoria tipo=”DDR” unit=”Mb”>512</memoria>
BENE!! OVVIAMENTE LA PRIMA FORMA!!
possiamo anche scrivere le stesse informazioni così:
è più utilizzata perchéunit=”Mb” qta=”512”/> negli
<memoria tipo=”DDR” si tende a inserire
oppure cosi: delle proprietà che riguardano il valore
attributi
contenuto nel tag, evitando cosi di andare a
<memoria>
modificare il valore di un attributo, meno
<tipo>DDR</tipo>
<unit>Mb</unit>
flessibile di un testo contenuto in un tag, o di
<qta>512</qta>
dover analizzare la stringa “512Mb DDR” come
</memoria>
oppure cosi ancora: nell’ultimo caso.
<memoria>512Mb DDR</memoria>
Qual è secondo voi la rappresentazione migliore?
Eidon School 15
16. Sezioni CDATA
Possiamo notare una sezione CDATA (Character Data):
<descrizione><![CDATA[ questo è
un ottimo <<PC>>!]]>
</descrizione>
Questa è utilizzata per inserire del testo in cui sono
presenti anche caratteri particolari come “&”, “<”,
“>” senza che siano interpretati come riferimenti a
markup.
Deve iniziare con “<![CDATA[”.
E terminare con “]]>”.
Non può contenere al suo interno la stringa “]]>”.
Eidon School 16
17. Entità 1/2
Cosa succede se scrivo <alert>Il totale è < 0</alert> ?
server.dtd:
<!ENTITY jvmRoute "rcstom01cinematv">
Per poter usare caratteri significativi per XML si usano le entità:
<!ENTITY le predefinite <(<) >(>) &(&) "(“)
Cinque sono SHUTDOWNport "8419">
<!ENTITY HTTPport "8097">
'(‘)
<!ENTITYusato per dichiarare entità:
Il DTD viene AJPport "8031">
<!ENTITY fnof "ƒ">
conf/server.xml:
<!ENTITY coordinate "((x, y) | (y, x) | (q, r) | (r, q))“ >
<!DOCTYPE Server SYSTEM "../server.dtd">
<Server port="&SHUTDOWNport;“
shutdown="SHUTDOWN">
Dove lo abbiamo già visto?
Eidon School 17
19. Entità 2/2
È possibile inserire come entità anche un intero
documento, anche esterno:
<!ENTITY footer SYSTEM
"http://www.oreilly.com/boilerplate/footer.xml">
Eidon School 19
20. I tipi di documento XML
I documenti XML possono essere di due tipi:
Ben Formati: è il documento che rispetta le regole di
XML (non può altrimenti essere un documento xml!).
Validi: oltre a essere ben formati deve anche
rispondere correttamente ad un controllo semantico
che permette di sapere se il documento ha un
significato rispetto a quello che vogliamo. Un
programma di elaborazione matematica gestisce
l’importazione di documenti XML contenenti
determinati tag, diversi per un programma bancario.
Questo controllo è opzionale.
Eidon School 20
21. Le regole di XML per documenti well-format
L’intero documento deve essere racchiuso in un unico tag
radice.
I tag devono essere annidati in maniera corretta, ogni tag di
apertura deve essere seguito dal suo di chiusura dentro i quali
possono esserci altri tag sempre annidati in maniera corretta.
Gli attributi possono essere solo inseriti nei tag di apertura.
Lo stesso attributo non può comparire più di una volta
all’interno dello stesso tag.
Ogni attributo inserito deve avere un valore e deve essere
racchiuso tra doppi o singoli apici.
I nomi dei marcatori e degli attributi sono Case Sensitive.
Eidon School 21
22. DOC TYPE
Un documento valido deve avere un DTD (o,
come vedremo più avanti, un XML Schema)
con cui può essere validato
Il DOCTYPE deve essere inserito tra l’xml
declaration e il root element
Subito dopo “<!DOCTYPE” è presente in
nome del tag di root del documento
SYSTEM o PUBLIC?
Eidon School 22
23. DOCTYPE: esempi
XHTML 1.0 Strict
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
XHTML 1.0 Transitional
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
transitional.dtd">
XHTML 1.0 Frameset
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
frameset.dtd">
XHTML 1.1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Eidon School 23
24. DOCTYPE: esempi
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-
strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en">
<head>
<title>XHTML 1.0 Example</title>
….
Eidon School 24
25. DOCTYPE: esempi
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>CommunityAtCasa</display-name>
…
Eidon School 25
27. Il problema
In un unico documento XML possiamo rappresentare
informazioni di natura diversa:
<autovettura>
<modello type="I">Honda CRW</modello>
<pneumatici>
<modello>Pirelli P9999</modello>
</pneumatici>
</autovettura>
Come distinguere i vari tag in base al loro significato?
Eidon School 27
28. La soluzione
Per dare un significato differente ai vari tag si usano dei prefissi,
identificatori posti prima del nome del marcatore e separati dai “:”
da quest’ultimo:
<?xml:namespace ns="http://some/uri1" prefix="au"?>
<?xml:namespace ns="http://some/url2" prefix="pn"?>
<au:autovettura>
<au:modello type="I">Honda CRW</au:modello>
<pn:pneumatici>
<pn:modello>Pirelli P9999</pn:modello>
</pn:pneumatici>
</au:autovettura>
Eidon School 28
29. Namespace
È una recommendation di W3C dal 1999.
La direttiva “xml:namespace” indica a quale URI
(Uniform Resource Identifier) si riferisce un
determinato prefisso. Si usa un URI perché unico in
Internet.
Un marcatore che usa un prefisso di dice che ha un
“nome qualificato”.
Si può specificare anche al suo primo utilizzo e/o
dentro un tag (e ha validità solo nei nodi figli):
<au:autovettura xmlns:au="http://some/uri">
Eidon School 29
30. Namespace di default
Tutti i tag che non hanno un prefisso appartengono
al namespace di default.
Il namespace di default può anche essere dichiarato
attraverso la parola chiave riservata xmlns NON
seguita da prefisso:
<autovettura xmlns="http://some/uri">
Il namespace di default non dichiarato ha l’URI ""
Eidon School 30
31. Namespace e attributi
I namespace si possono applicare anche agli
attributi:
<au:modello au:type="I">Honda CRW</au:modello>
Il namespace di default non si applica agli attributi
privi di prefisso.
Se relativi a namespace diversi, e che puntano a URI
diversi, gli attributi possono avere nome locale
uguale.
Eidon School 31
32. Un esempio
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>msite</display-name>
<description>
MSITE - sito mobile della gazzetta dello sport
</description>
…
Eidon School 32
33. Facciamo un altro esempio!
<!-- http://www.w3.org is bound to n1 and n2 and is the
default -->
<x xmlns:n1="http://www.w3.org"
xmlns:n2="http://www.w3.org"
xmlns="http://www.w3.org" >
<alex a="1" b="2" />
<frantz a="1" n1:a="2" />
<ficarra a="1" a="2" />
<picone n1:a="1" n2:a="2" />
</x>
Eidon School 33
37. Mai visto qualcosa del genere?
Simbolo dell'euro € …€…
€ anche questo è il simbolo dell’euro!!
Vari “?”
<?xml version='1.0' encoding='UTF-8'?>
Quante volte vi hanno detto che su una
pagina html/xml le accentate non si
vedono?
Eidon School 37
38. Character-Set
Quasi tutti i caratteri di ogni lingua sono codificati
nello standard UNICODE che associa un numero ad
un simbolo
L’encoding dice come quel numero è scritto
fisicamente nel file
I parser XML possono applicare un meccanismo di
auto-detection dell’encoding (anche grazie al Byte
Order Mark di UTF)
MIME Type text/xml -> US-ASCII, applicazion/xml -> Il
client tenta di capire l’econding come nel punto
precedente
Eidon School 38
39. Encoding declaration
<?xml version="1.0" encoding="ISO-8859-1"?>
È caldamente consigliato dichiarare l’encoding
Se non viene fatto, il default è UTF-8 o UTF-16
Un XML scritto con caratteri ASCII puri non ha
problemi a non dichiarare l’encoding…ma è,à,ù,€
non fanno parte di ASCII 7 bit!
ASCII: <città>Mondovì più Como</città>
Letto da UTF-8: <città >Mondovì più Como</città >
Letto da Latin1: <citt?>Mondov? pi? Como</citt?>
Eidon School 39
40. Character References 1/2
Da la possibilità di inserire un carattere usando il
codice UNICODE:
њ decimale
њ esadecimale
Non può essere usato nei nomi di tag e attributi
Può essere usato nelle Entità:
<!ENTITY sigma "σ"> (σ)
Eidon School 40
41. Character References 2/2
Esempio (proverbio greco):
<maxim>σοφός
έαυτόν
γιγνώσ&
#x3BA;ει</maxim>
“The wise man knows himself”
Eidon School 41
44. CSS e XSL
L’importanza che il W3C ha dato alla separazione
delle informazioni in dati e presentazione ha portato
la necessita di sviluppare nuove tecnologie capaci di
supportare tale divisione. Nasce cosi CSS per HTML,
seguito da XSL per XML, due tecnologie chiave per il
futuro del web, il web semantico, in cui le macchine
sono capaci di comprendere e trattare le
informazioni senza la fatica di dover riconoscerle tra
le parti di formattazione.
Eidon School 44
45. XSL
È una famiglia di linguaggi per la trasformazione e
presentazione di documenti XML, si compone di:
XPath: recupera determinati elementi di un XML
XSLT: Trasforma i file XML in altri formati
XSL-Fo: Formattazione
Non sostituisce il CSS, l’XSL è molto utile per
trasformare nella forma i contenuti, mentre il
CSS resta per assegnare gli stili di formattazione ai
tag HTML.
Eidon School 45
46. XPath
Sintassi per localizzare elementi o attributi in
documenti XML
Namespaces aware
String-based (non XML)
Riesce a manipolare stringhe, valutare espressioni
booleane o far calcoli sui nodi o sui loro contenuti.
Usato anche da altre tecnologie come XSLT e
XPointer
È considerato l’SQL di XML
Eidon School 46
47. XSLT
Raccomandazione del W3C (1.0) del novembre 1999 .
W3C: “Linguaggio per trasformate un documento
XML in un altro documento sempre XML”, ma fa
molto altro! (unire due documenti XML, ordinare
elementi, filtrarli, crearne di nuovi, cambiare
strutturalmente il documento).
Namespace: “http://www.w3.org/1999/XSL/Transform”.
È spesso utilizzato per trasformare un XML in
XHTML per la visualizzazione sul web.
La trasformazione di un XML attraverso un XSLT
viene effettuata dal parser XML.
Eidon School 47
48. XSL-Fo
Raccomandazione del W3C dell’ottobre 2001.
Namespace: xmlns:fo=“http://www.w3.org/1999/XSL/Format”
Trasforma un documento XML in uno Formattato
secondo un determinato XSL-Fo.
Formati di output:
PostScript
PDF
Testo
PCL
RTF
…
Eidon School 48
49. XMLSchema
Linguaggio per definire delle regole di validità per documenti
XML
W3C Raccommendation dal 2001
Più potente del DTD (datatypes…)
È XML quindi manipolabile come qualunque altro documento
XML
Supporta i namespaces
Estensibile
Uno schema può validare anche solo una porzione di
documenti in cui è definito un namespace, viceversa, uno
documento XML può avere molti XSD per i diversi namespace
che ingloba.
Eidon School 49
50. Java & XML
Parser DOM, SAX, StAX, TrAX
Eidon School 50
51. Parser: DOM vs. SAX
Quando usare DOM:
Per percorrere l’albero avanti e indietro
Manipolare il documento in molte parti
Si ha a disposizione molta memoria perché
l’albero XML viene ricostruito in essa
Creare un nuovo documento
Quando usare SAX:
Percorrere l’albero solo “forward only”
Leggere solo poche informazioni
Si ha poca memoria a disposizione
Eidon School 51
53. Riferimenti
XML in a Nutshell, 3rd Edition (ISBN: 0-596-00764-7)
http://en.wikipedia.org/wiki/Standard_Generalized_M
arkup_Language
http://www.sgmlsource.com/history/roots.htm
Eidon School 53
The Standard Generalized Markup Language ( ISO 8879:1986 SGML ) is an ISO Standard metalanguage in which one can define markup languages for documents. SGML is a descendant of IBM 's Generalized Markup Language (GML), developed in the 1960s by Charles Goldfarb, Edward Mosher and Raymond Lorie (whose surname initials were used by Goldfarb to make up the term GML[1]). SGML provides an abstract syntax that can be implemented in many different concrete syntaxes. For instance, although it is the norm to use angle brackets as tag delimiters in an SGML document (per the reference concrete syntax defined in the standard), it is possible to use other characters instead, provided that a suitable concrete syntax is defined in the document's SGML declaration.[2] For example, an SGML interpreter could be programmed to parse GML markup. In GML, tags are bounded by a colon on the left and a full stop on the right; an e prefix denotes an end tag: :xmp.Hello, world:exmp..
Lo S tandard G eneralized M arkup L anguage ( SGML ), è uno standard per la descrizione logica dei documenti . Discende dal Generalized Markup Language della IBM . L'idea centrale dello standard è un tipo di marcatura generica chiamata "marcatura descrittiva" che definisce la struttura logica dei documenti. L'organizzazione di un documento non è espressa usando la codifica dei sistemi di scrittura, che è finalizzata alla presentazione grafica, ma sono evidenziate le parti in cui è strutturato il documento (ad esempio paragrafi, capitoli) insieme ad altre particolarità del testo (come note, tabelle, intestazioni). Sono stati creati a questo scopo programmi come Alml , cioè sistemi di composizione SGML. Utilizzo originale Una porzione dell' OED ( 1985 ) con la sintassi SGML evidenziata SGML fu inizialmente sviluppato per permettere lo scambio di documenti machine-readable (leggibili da un computer) in progetti governativi, legali e industriali, che devono rimanere leggibili per diverse decadi (un periodo di tempo molto lungo nell'ambito dell' informatica ). Inizialmente usato per pubblicazione di testo e basi di dati , una delle sue maggiori applicazioni fu la seconda edizione dell' Oxford English Dictionary (OED), che era ed è interamente formattato usando un linguaggio SGML. Generalized Markup Language ( GML ) is a set of macros that implement intent-based markup tags for the IBM text formatter , SCRIPT/VS . SCRIPT/VS is the main component of IBM's Document Composition Facility (DCF). A starter set of tags in GML is provided with the DCF product. GML was developed in the 1960s by Charles Goldfarb , Edward Mosher and Raymond Lorie (whose surname initials were used by Goldfarb to make up the term GML [1] ). GML simplifies the description of a document in terms of its format, organization structure, content parts and their relationship, and other properties. GML markup (or tags) describes such parts as chapters, important sections, and less important sections (by specifying heading levels), paragraphs, lists, tables, and so forth. GML frees document creators from specific document formatting concerns such as font specification, line spacing, and page layout required by SCRIPT/VS. Using GML, a document is marked up with tags that define what the text is, in terms of paragraphs , headers , lists , tables , and so forth. The document can then be automatically formatted for various devices simply by specifying a profile for the device. For example, it is possible to format a document for a laser printer or a line ( dot matrix ) printer or for a screen simply by specifying a profile for the device without changing the document itself. A later and more extensive set of tags is provided by IBM's BookMaster product. GML preceded and was one of the two sources that were used as the basis for the industry-developed Standard Generalized Markup Language (SGML), a set of rules for creating structured document description languages . The Extensible Markup Language (XML) was initially a streamlined and simplified development of SGML, but has outgrown its parent in terms of worldwide acceptance and support. Derivatives XML Main article: XML XML is a subset of SGML, designed so as to make the parser much easier to implement than a full SGML parser. A consequence of the ease of implementation is that XML, rather than SGML, is nowadays widely used for deriving document specifications. Contributing to this is also the fact that few SGML-aware programs existed when XML was created. The number of XML applications today is large. XML also has a lightweight internationalization . XML is used for general-purpose applications, such as the Semantic Web , XHTML , SVG , RSS , Atom , XML-RPC and SOAP .
http://www.w3c.org Un’organizzazione fondata nel 1994 da TIM BERNERS-LEE in collaborazione con MIT (USA), INRIA (Francia) e Keio University (Giappone) al fine di “sviluppare protocolli comuni per migliorare l’interoperabilità e guidare l’evoluzione del World Wide Web” Il W3C produce sia specificazioni di interoperabilità, sia codice d’esempio. Il W3C ha circa 450 organizzazioni membre, includendo università, enti di ricerca, produttori di hardware e software, società di telecomunicazione, fornitori di contenuti, corporation, e enti governativi. UniBo-CS è membro dal 1999. Esiste un’organizzazione sorella, IW3C2 ( International World Wide Web Conference Committee ) che organizza conferenze scientifiche ed altri eventi a livello locale e internazionale.
2.8 Processing Instructions In HTML, comments are sometimes abused to support nonstandard extensions. For instance, the contents of the script element are sometimes enclosed in a comment to protect it from display by a nonscript-aware browser. The Apache web server parses comments in .shtml files to recognize server-side includes. Unfortunately, these documents may not survive being passed through various HTML editors and processors with their comments and associated semantics intact. Worse yet, it's possible for an innocent comment to be misconstrued as input to the application. XML provides the processing instruction as an alternative means of passing information to particular applications that may read the document. A processing instruction begins with <? and ends with ?>. Immediately following the <? is an XML name called the target , possibly the name of the application for which this processing instruction is intended or possibly just an identifier for this particular processing instruction. The rest of the processing instruction contains text in a format appropriate for the applications for which the instruction is intended. For example, in HTML, a robots META tag is used to tell search-engine and other robots whether and how they should index a page. The following processing instruction has been proposed as an equivalent for XML documents: <?robots index="yes" follow="no"?> The target of this processing instruction is robots. The syntax of this particular processing instruction is two pseudo-attributes, one named index and one named follow, whose values are either yes or no. The semantics of this particular processing instruction are that if the index attribute has the value yes, then search-engine robots should index this page. If index has the value no, then robots should not index the page. Similarly, if follow has the value yes, then links from this document will be followed; if it has the value no, they won't be. Other processing instructions may have totally different syntaxes and semantics. For instance, processing instructions can contain an effectively unlimited amount of text. PHP includes large programs in processing instructions. For example: <?php mysql_connect("database.unc.edu", "clerk", "password"); $result = mysql("HR", "SELECT LastName, FirstName FROM Employees ORDER BY LastName, FirstName"); $i = 0; while ($i < mysql_numrows ($result)) { $fields = mysql_fetch_row($result); echo "<person>$fields[1] $fields[0] </person>\\r\\n"; $i++; } mysql_close( ); ?> Processing instructions are markup, but they're not elements. Consequently, like comments, processing instructions may appear anywhere in an XML document outside of a tag, including before or after the root element. The most common processing instruction, xml-stylesheet, is used to attach stylesheets to documents. It always appears before the root element, as Example 2-6 demonstrates. In this example, the xml-stylesheet processing instruction tells browsers to apply the CSS stylesheet person.css to this document before showing it to the reader. Example 2-6. An XML document with a processing instruction in its prolog <?xml-stylesheet href="person.css" type="text/css"?> <person> Alan Turing </person> The processing instruction names xml, XML, XmL, etc., in any combination of case, are forbidden in order to avoid confusion with the XML declaration. Otherwise, you're free to pick any legal XML name for your processing instructions.
http://www.w3.org/TR/2004/REC-xml11-20040204/#NT-ExternalID Standard DTDs may actually be stored at multiple URLs. For example, if you're drawing an SVG picture on your laptop at the beach, you probably want to validate the drawing without opening a network connection to the W3C's web site where the official SVG DTD resides. Such DTDs may be associated with public IDs. The name of the public ID uniquely identifies the XML application in use. At the same time, a backup URL is also included in case the validator does not recognize the public ID. To indicate that you're specifying a public ID, use the keyword PUBLIC in place of SYSTEM. For example, this document type declaration refers to the Rich Site Summary DTD standardized by Netscape: <!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd"> A local catalog server can convert the public IDs into the most appropriate URLs for the local environment. The catalogs themselves can be written in XML, specifically the OASIS XML catalog format ( http://www.oasis-open.org/ committees / entity / spec.html ). In practice, however, PUBLIC IDs aren't used very much. Most of the time, validators rely on the URL to actually validate the document. If that is true then why have a PUBLIC identifier at all ? What is their purpose beware that you are skirting on the edge of a very deep "debate":-) Basically the public identifier gives a unique canonical name for the dtd that you can recognise; whereas the SYSTEM identifier may well point at a local path on the original author's system that doesn't make sense on yours. An XML parser may use either (or both) identifiers to find the file. So if you have an xml parser that has an xml catalogue of some sort that recognises say XHTML or Docbokk PUBLIC identifier, the file will work even if the system ID points at a file not accessable to you as your parser can use the catalogue to map the public ID to a local copy. Conversely if you don't have that public id in your catalogue (or if there is no public id) then you can perhaps find the file directly by using the system id. When the syntax was invented, for sgml, this last step would most likely fail as it would be a local file name so it would assume that you had local files in the same position. In XML when the SYSTEM is supposed to be a URI and so perhaps usable from anywhere in the world there is an argument (that I don't personally hold, but which is not unreasonable, and comes up often) that the SYSTEM ID is all you need and PUBLIC IDs no longer serve a purpose.
http://www.w3.org/TR/REC-xml-names/
Questa è la cosa che tra più in inganno chi scrive software, infatti il programma va quasi sempre e ogni tanto “si rompe”, come mai? La ragione sta nel fatto che sia ISO-8859-1(5) che UTF-8 usano la stessa rappresentazione binaria per i caratteri ASCII (è una scelta voluta per ragioni di efficienza e compatibilità) per cui non c’è differenza fra l’encoding in UTF-8 e ISO-8859-1 per i caratteri più comunemente utilizzati. http://www.w3.org/TR/REC-xml/#sec-guessing-no-ext-info
http://www.w3.org/TR/REC-xml/#sec-guessing-no-ext-info Since ASCII is almost never an appropriate character set for an XML document, application/xml is much preferred over text/xml. Unfortunately, most web servers including Apache 2.0.36 and earlier are configured to use text/xml by default. If you're running such a version you should probably upgrade before serving XML files. [1] Therefore, an XML parser will attempt to guess the character set based on the first several bytes of the document. The main checks the parser makes include the following: If the first two bytes of the document are #xFEFF, then the parser recognizes the bytes as the Unicode byte-order mark. It then guesses that the document is written in the big-endian, UTF-16 encoding of Unicode. With that knowledge, it can read the rest of the document. If the first two bytes of the document are #xFFFE, then the parser recognizes the little-endian form of the Unicode byte-order mark. It now knows that the document is written in the little-endian, UTF-16 encoding of Unicode, and with that knowledge it can read the rest of the document. If the first four bytes of the document are #x3C3F786D, that is, the ASCII characters <?xm, then it guesses that the file is written in a superset of ASCII. In particular, it assumes that the file is written in the UTF-8 encoding of Unicode. Even if it's wrong, this information is sufficient to continue reading the document through the encoding declaration and find out what the character set really is.