[Ocaml-pxp-users] adding comment to a document

Gerd Stolpmann info at gerd-stolpmann.de
Tue Jul 8 03:55:08 PDT 2003


Am Mon, 2003-06-30 um 18.45 schrieb Stefano Zacchiroli:
> I would like to create a PXP document representing the following XML
> document:
> 
>   <?xml version="1.0"?>
>   <?foo an useless processing instruction?>
>   <!-- an useless comment -->
>   <empty />
> 
> The issue I'm facing is that the document object has a method to add
> processing instruction, but seems to have no method to add comments ...

You need a "super root node" to add comments. This is an optional node
above the root node (here "empty"), and below the document object. With
such a node, you would have the tree

- document object
   |
   +-- super root node
        |
        +-- processing instr. "<?foo ...?>"
        +-- comment "<!-- an useless comment -->"
        +-- element "empty"

This is just a more exact representation of the XML text that is often
not needed, but sometimes very useful.

> BTW a changelog entry in pxp_document.mli states that
> init_xml_standalone method has been removed from the document class. I
> guess this is because the standalone declaration is accessibile trhough
> Pxp_dtd.dtd objects.

Yes, if you view the dtd object as a collection of constraints, it is
very logical to make the "standalone" constraint part of this object.

> Two questions at this regard:
> - is therefore still useful to have both standalone and dtd values in
>   the E_start_tag events of the event based parser? (or is only kept for
>   backward compatibility?)

Good question. I have no real answer. Anyway, it is not a big problem.
If you generate events, you must ensure that the event stream has a
certain structure (e.g. there must be an E_end_tag for every
E_start_tag). That the standalone flag in the E_start_doc event must be
equal to the corresponding flag in the dtd object is just another
condition.

Maybe these conditions should be formulated somewhere.

> - is there no way to set a standalone declaration for a document without
>   a DTD? (I know that this is really useless because you must have a DTD
>   as soon as you init the root element, but ... just for curiosity :-)

Does this question make sense? The standalone declaration ensures that
there are no external declarations that change the meaning of the
document (e.g. by setting defaults for attributes, or redirecting
entities). So a document without a DTD is always standalone, you just
cannot do any of the things that are forbidden by the standalone
declaration.

Gerd
-- 
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany 
gerd at gerd-stolpmann.de          http://www.gerd-stolpmann.de
------------------------------------------------------------




More information about the Ocaml-pxp-users mailing list