Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Caml-list] Q: type conversion with Gdome

1 view
Skip to first unread message

Yang Shouxun

unread,
Jul 16, 2008, 5:08:04 AM7/16/08
to caml...@inria.fr
Hello everyone,

I've been using Gdome for some time now and I always find it difficult to deal
with the type system. Here is the issue:

The document class has a
method getElementsByTagName :
tagname:Gdome.domString -> Gdome.nodeList
and from a nodeList object I can only get Gdome.node objects, while we know
they should be Gdome.element objects.

My question is how to convert from Gdome.node to Gdome.element?

P.S. Gdome.element can be converted to Gdome.node, but not in the other
direction as far as I know.

TIA,

shouxun

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Claudio Sacerdoti Coen

unread,
Jul 16, 2008, 5:44:37 AM7/16/08
to Yang Shouxun, caml...@inria.fr
Dear Yang,

not every node is an element. Thus you need to use dinamic cast:

let node = ... in
(* next line may raise GdomeInit.DOMCastException *)
let element = Gdome.element_of_node node in
...

Cheers,
C.S.C.

--
----------------------------------------------------------------
Real name: Claudio Sacerdoti Coen
Doctor in Computer Science, University of Bologna
E-mail: sace...@cs.unibo.it
http://www.cs.unibo.it/~sacerdot
----------------------------------------------------------------

Yang Shouxun

unread,
Jul 16, 2008, 9:37:25 PM7/16/08
to caml...@yquem.inria.fr
On Wednesday 16 July 2008 17:44:18 Claudio Sacerdoti Coen wrote:
> Dear Yang,
>
> not every node is an element. Thus you need to use dinamic cast:
>
> let node = ... in
> (* next line may raise GdomeInit.DOMCastException *)
> let element = Gdome.element_of_node node in
> ...

Thank you very much. I haven't noticed element_of_node. As
Gdome.element_of_node is a class and there is no equivalent function, thus my
final version is like is:

let element = new Gdnome.element_of_node node in

0 new messages