Subject: Re: [SWIPL] XML Parser

From: Jan Wielemaker <[email-masked]>
Date: Tue, 13 Mar 2001 09:54:11 +0100

On Tue, 13 Mar 2001, Richard A. O'Keefe wrote:
>Alberto Ruiz Cristina <[email-masked]> wrote:
>    <br>Will I be able to validate XML files with that DTD?
>
>SWI Prolog's SGML/XML parser does not perform all the checks that
>a validating parser should do, but it delivers the same Infoset that
>a validating parser would.
>
>	<br>I am thinking about developing a simple XML parser that,
>	given the name of a general element from the DTD, returned that
>	particular element in an XML document.  How could I solve the
>	identification problem?  (there can be different elements with
>	the same name in a document structure)
>
>I cannot understand this.  What on earth can "THAT PARTICULAR ELEMENT" mean?
>The world is full of simple XML parsers (you can write a non-validating XML
>parser in under a day in less than a thousand lines of C, including blank
>lines and comments; I've done it).
>
>If you want to pick some element out of a document, you must somehow
>describe it well enough to locate it.  The element type (also known as GI)
>of a node is sufficient to locate it only if the grammar ensures that there
>is at most one element of that type.
>
>If the element has an ID attribute, then the value of that attribute is
>sufficient to locate the element.

Dunno what Alberto means either, but under some circumstances you
can pick an element from a file without loading the entire file.  You
do this running the parser in call-back mode, until you find the
<begin> of the element you want.  At that moment you make it read the
next element.  I think there is a demo of this mixed call-back/reading
in the documentation.

One thing I've used this for is to make an index of `interesting'
elements (I my case RDF descriptions) using the call-back interface. 
If I need a description I open the file, seek to the recorded
location and read the element.  Later I reverted to using a database
holding the RDF triples, but still I think there are cases this is a
sensible approach.

	--- Jan