From jan@swi.psy.uva.nl Tue Mar 13 10:01:16 2001
Received: from gollem.swi.psy.uva.nl (root@gollem [145.18.152.30])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f2D91GZ22545;
	Tue, 13 Mar 2001 10:01:16 +0100 (MET)
Received: from localhost (localhost [[UNIX: localhost]])
	by gollem.swi.psy.uva.nl (8.9.3/8.9.3/SuSE Linux 8.9.3-0.1) id KAA25770;
	Tue, 13 Mar 2001 10:01:16 +0100
From: Jan Wielemaker <jan@swi.psy.uva.nl>
Organization: SWI, University of Amsterdam
To: "Richard A. O'Keefe" <ok@atlas.otago.ac.nz>, aruiz@isys.dia.fi.upm.es,
   prolog@swi.psy.uva.nl
Subject: Re: [SWIPL] XML Parser
Date: Tue, 13 Mar 2001 09:54:11 +0100
X-Mailer: KMail [version 1.0.28]
Content-Type: text/plain
References: <200103122345.MAA08977@atlas.otago.ac.nz>
In-Reply-To: <200103122345.MAA08977@atlas.otago.ac.nz>
MIME-Version: 1.0
Message-Id: <01031310011500.25506@gollem>
Content-Transfer-Encoding: 8bit

On Tue, 13 Mar 2001, Richard A. O'Keefe wrote:
>Alberto Ruiz Cristina <aruiz@isys.dia.fi.upm.es> 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

