18 Giu

XML Well-Formed

Fonte: www.vitruviantux.net

Perché mai un post sulla “formattazione” corretta di un documento XML?Flow of data in a typical parser
Perché alle volte è bene avere presenti questi particolari, soprattutto per non farsi male quando si vanno ad utilizzare parser vari ed eventuali..

Un documento XML si dice well-formed (ed è quindi analizzabile da un parser) se:

  • Non-empty elements are delimited by both a start-tag and an end-tag.
  • Empty elements may be marked with an empty-element (self-closing) tag, such as <IAmEmpty />. This is equal to <IAmEmpty></IAmEmpty>.
  • All attribute values are quoted with either single (’) or double (”) quotes. Single quotes close a single quote and double quotes close a double quote.
  • Tags may be nested but must not overlap. Each non-root element must be completely contained in another element.
  • The document complies with its declared character encoding. The encoding may be declared or implied externally, such as in “Content-Type” headers when a document is transported via HTTP, or internally, using explicit markup at the very beginning of the document. When no such declaration exists, a Unicode encoding is assumed, as defined by a Unicode Byte Order Mark before the document’s first character. If the mark does not exist, UTF-8 encoding is assumed.
  • Element names are case-sensitive.

(Tratto da Wikipedia)

Ovviamente se volete far leggere un documento XML non well-formed ad un qualsivoglia Parser, sia questo SAX o DOM, otterrete un errore. Per ovviare a ciò potete:

  1. Introdurre delle sequenze di escape per gli elementi,
  2. Modificare il documento (o crearne uno nuovo) strutturandolo in modo corretto.

Che io sappia non ci sono altre alternative (se ne avete segnalatemele che fanno sempre comodo) e per interpretare documenti strutturati non correttamente si deve passare necessariamente da una delle 2 soluzioni.

Un unico dubbio mi assilla (esageriamo via..) ma una pagina jsp che può contenere tag del tipo

<%= variabile_di_tipo_string >

come verrà parsato? Userà uno dei due metodi precedenti o si saranno riscritti un parser che non necessita la proprietà di buona formattazione? (mi sembra una bischerata sinceramente..).

Vabbè al momento non è il mio problema principale )

Molto presto credo che parlerò di XSLT.. stay tuned!


Segnala presso:
Aggiungi 'XML Well-Formed' a Del.icio.usAggiungi 'XML Well-Formed' a diggAggiungi 'XML Well-Formed' a FURLAggiungi 'XML Well-Formed' a blinklistAggiungi 'XML Well-Formed' a redditAggiungi 'XML Well-Formed' a Feed Me LinksAggiungi 'XML Well-Formed' a TechnoratiAggiungi 'XML Well-Formed' a Yahoo My WebAggiungi 'XML Well-Formed' a NewsvineAggiungi 'XML Well-Formed' a SocializerAggiungi 'XML Well-Formed' a Ma.gnoliaAggiungi 'XML Well-Formed' a Stumble UponAggiungi 'XML Well-Formed' a Google BookmarksAggiungi 'XML Well-Formed' a RawSugarAggiungi 'XML Well-Formed' a SquidooAggiungi 'XML Well-Formed' a SpurlAggiungi 'XML Well-Formed' a BlinkBitsAggiungi 'XML Well-Formed' a NetvouzAggiungi 'XML Well-Formed' a RojoAggiungi 'XML Well-Formed' a BlogmarksAggiungi 'XML Well-Formed' a Shadows
Aggiungi 'XML Well-Formed' a Co.mmentsAggiungi 'XML Well-Formed' a ScuttleAggiungi 'XML Well-Formed' a BloglinesAggiungi 'XML Well-Formed' a TailrankAggiungi 'XML Well-Formed' a SegnaloAggiungi 'XML Well-Formed' a OKnotizieAggiungi 'XML Well-Formed' a NetscapeAggiungi 'XML Well-Formed' a Bookmark.itAggiungi 'XML Well-Formed' a AskAggiungi 'XML Well-Formed' a SmarkingAggiungi 'XML Well-Formed' a LinkagogoAggiungi 'XML Well-Formed' a DeliriousAggiungi 'XML Well-Formed' a SocialdustAggiungi 'XML Well-Formed' a Live-MSNAggiungi 'XML Well-Formed' a SlashDotAggiungi 'XML Well-Formed' a SphinnAggiungi 'XML Well-Formed' a DiggitaAggiungi 'XML Well-Formed' a SeotribuAggiungi 'XML Well-Formed' a FaceBookAggiungi 'XML Well-Formed' a Upnews

Continua a leggere..

Nessun Commento »

Puoi lasciare una risposta, oppure fare un trackback dal tuo sito.


Vuoi essere il primo a lasciare un commento per questo articolo? Utilizza il modulo sotto..

Lascia un commento

XHTML: Puoi utilizzare questi tag: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>