[Ocaml-pxp-users] Several questions about PXP API

Gerd Stolpmann info at gerd-stolpmann.de
Mon May 16 05:22:44 PDT 2005


Am Samstag, den 14.05.2005, 11:52 +0100 schrieb Richard Jones: 
> I'm using roughly the following PXP code to generate a SOAP document.
> The output it produces (reproduced below) isn't really a good XML
> document.
> 
> I tried creating a full "'a document", but kept getting the error
> Fatal error: exception Failure("#write: DTD without root")
> 
> Can anyone show me how to make a simple document?

Currently, documents must have a DTD - this is a consequence of the
validation-centric view of PXP. document#write always tries to print a
DOCTYPE line, and if the DTD isn't properly initialised you get the
error you saw.

If you really need documents for non-validation purposes, ensure that
the DTD has some minimum initialisation:

- call dtd#set_root with the name of the root element (you can defer
  this until you know the root element)
- call dtd#allow_arbitrary to disable validation (makes the ~valcheck
  arguments superfluous)

> Secondly, what I really want to do is use namespaces.  I basically
> altered the code below to use default_namespace_spec and
> default_namespace_config.  However any attempt to use namespaces
> results in this message at runtime:
> Fatal error: exception Pxp_core_types.Namespace_method_not_applicable("namespace_manager")

You must setup another thing, the so-called namespace manager. This is
mainly a table mapping namespace prefixes to namespace URIs. Simply do:

( match cfg.enable_namespace_processing with
      Some mng -> dtd # set_namespace_manager mng
    | None     -> ()
)

when cfg is the config record.

> Can someone show me some simple code which just parses a document with
> namespaces and then (for example) prints it out?

This would not have helped you. The parser functions do the whole
"magic" setup of the DTD automatically, so you would not have seen this
code.

Gerd
> 
> ----------------------------------------------------------------------
> let dtd =
>   new Pxp_dtd.dtd Pxp_types.default_config.Pxp_types.warner
>     Pxp_types.default_config.Pxp_types.encoding
> 
> let create_element name =
>   Pxp_document.create_element_node ~valcheck:false
>     Pxp_tree_parser.default_spec dtd name []
> let create_data data =
>   Pxp_document.create_data_node Pxp_tree_parser.default_spec dtd data
> 
> let soap_call name params =
>   (* Generate the envelope. *)
>   let env = create_element "Envelope" in
>   let body = create_element "Body" in
>   env#set_nodes [body];
>   let call = create_element name in
>   body#set_nodes [call];
>   call#set_nodes (Array.to_list params);
> 
>   (* Generate the SOAP message. *)
>   let buf = Buffer.create 1024 in
>   env#write (`Out_buffer buf) `Enc_utf8;
>   let data = Buffer.contents buf in
> 
>   print_endline data
> ----------------------------------------------------------------------
> 
> <Envelope
> ><Body
> ><show
> ><campaign
> ><dailyBudget
> >10</dailyBudget
> ><id
> >11</id
> ></campaign
> ></show
> ></Body
> ></Envelope
> >
> 
> 
-- 
------------------------------------------------------------
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