[Ocaml-pxp-users] [repost] Creating a simple document with namespaces
Richard Jones
rich at annexia.org
Mon May 16 04:44:04 PDT 2005
My last query wasn't perhaps focused enough to generate any responses.
I'm finding the PXP API to be very hard to understand, even to do
apparently simple things.
I want to create and print out an XML document with namespaces. I
don't need validation or DTDs at this point.
Here is my test program:
----------------------------------------------------------------------
(* Namespace test.
* Compile with:
* ocamlc -I +pcre -I +equeue -I +netstring -I +netclient -I +pxp-lex-iso88591 -I +pxp-engine str.cma unix.cma pcre.cma equeue.cma netstring.cma netclient.cma pxp_engine.cma pxp_lex_iso88591.cma pxp_lex_link_iso88591.cmo test.ml -o test
*)
let dtd =
new Pxp_dtd.dtd Pxp_types.default_config.Pxp_types.warner
Pxp_types.default_config.Pxp_types.encoding
(* Helper functions for creating element and data nodes. *)
let create_element, create_data =
let dtd =
let collect_warnings = Pxp_types.default_config.Pxp_types.warner in
let rep_encoding = Pxp_types.default_config.Pxp_types.encoding in
new Pxp_dtd.dtd collect_warnings rep_encoding in
let exemplar = new Pxp_document.namespace_element_impl
Pxp_tree_parser.default_extension in
let create_element name =
exemplar#create_element ~valcheck:false
dtd (Pxp_document.T_element name) []
in
let create_data data =
exemplar#create_data dtd data
in
create_element, create_data
let () =
let env = create_element "Envelope" in
let body = create_element "Body" in
env#set_nodes [body];
let call = create_element "hello" in
body#set_nodes [call];
let params =
let id = create_element "id" in
id#set_nodes [create_data "1"];
let p1 = create_element "p1" in
p1#set_nodes [create_data "2"];
[ id; p1 ] in
call#set_nodes params;
let buf = Buffer.create 1024 in
env#write (`Out_buffer buf) `Enc_utf8;
let data = Buffer.contents buf in
print_endline ("XML request = \n" ^ data);
----------------------------------------------------------------------
When run this produces the oblique error message:
Fatal error: exception Pxp_core_types.Method_not_applicable("create_data")
How do I make this work?
Rich.
--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com
More information about the Ocaml-pxp-users
mailing list