[Ocaml-pxp-users] Question about interaction style with complex documents
Richard Jones
rich at annexia.org
Tue May 31 06:00:25 PDT 2005
[I'm still trying to parse WSDL files ...]
Part of the problem is trying to do pattern matching across multiple
levels of Pxp document. I end up with a lot of intractable code like
the code attached below (and that's "simplified" with lots of helper
functions).
There are two related problems here. Firstly the object access style
means I can't really use OCaml pattern matching, but instead have to
do:
match node#node_type with
| Pxp_document.T_element name when name = ... ->
and the second is that because I'm using namespaces I have to grab the
normprefix for the document and match on:
... when name = xsd ^ ":nodename" ->
It would all be a lot simpler if there was a way to (a) convert the
tree to a more convenient OCaml structure which would allow pattern
matching, and (b) normalise the namespace prefixes so that they are
what I expect (eg. "xsd:nodename").
I guess I can write code easily enough to do (a). I'm not sure
whether XML allows (b) to be possible.
So the question is how have people solved these problems? They must
surely be common with any serious XML work ...
Rich.
(I guess the other possibility is something like CDuce).
----------------------------------------------------------------------
match node#node_type with
| Pxp_document.T_element name when name = xsd ^ ":simpleType" ->
let restriction =
let subnodes = filter (xsd ^ ":restriction") node#sub_nodes in
match subnodes with
| [h] -> h
| _ ->
failwith "Xsd.parse: expecting a single <restriction> subnode" in
let base = get_attr "base" restriction in
let bt =
try parse_basic_type base
with Not_found ->
failwith ("Xsd.parse: expecting a basic type, but got " ^
base) in
(* If we have <enumeration> subnodes, then really it's an
* enumeration.
*)
let enums = filter (xsd ^ ":enumeration") restriction#sub_nodes in
let enums = List.map (get_attr "value") enums in
SimpleType (bt, enums)
| Pxp_document.T_element name when name = xsd ^ ":complexType" ->
(match node#sub_nodes with
| [] -> ComplexType Unix
| [n] when
n#node_type = Pxp_document.T_element (xsd ^ ":sequence") ->
ComplexType (Sequence (parse_sequence n))
| [n] when
n#node_type = Pxp_document.T_element (xsd ^ ":all") ->
ComplexType (All (parse_all n))
| _ ->
failwith "Xsd.parse: multiple subnodes of <complexType>")
--
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