Commit 432d1c02 authored by Pietro Abate's avatar Pietro Abate

[r2005-06-02 11:52:35 by afrisch] Field access for XML attibutes

Original author: afrisch
Date: 2005-06-02 11:52:35+00:00
parent 6a5dea60
Since 0.3.2
* Added split_atom, make_atom. Removed atom_of.
* Added char_of_int built_in function.
* Now int_of also accepts octal binary and hexadecimals
* Now int_of also accepts octal binary and hexadecimals.
* The field access also works for XML element attributes.
* Bug fix in configure
......@@ -302,7 +302,9 @@ and eval_xtrans_aux env brs acc = function
| _ -> acc
and eval_dot l = function
| Value.Record r -> LabelMap.assoc l r
| Value.Record r
| Value.Xml (_,Value.Record r,_)
| Value.XmlNs (_,Value.Record r,_,_) -> LabelMap.assoc l r
| v ->
Value.print Format.std_formatter v;
failwith ("Cannot find field " ^ (Label.to_string (LabelPool.value l)))
......@@ -874,12 +874,20 @@ and type_check' loc env e constr precise = match e with
type_check_string loc env 0 s i j e constr precise
| Dot (e,l) ->
let t = type_check env e Types.Record.any true in
let t =
try Types.Record.project t l
with Not_found -> raise_loc loc (WrongLabel(t,l))
verify loc t constr
let expect_rec = Types.record l (Types.cons constr) in
let expect_elt =
(Types.cons (Types.times (Types.cons expect_rec) Types.any_node)) in
let t = type_check env e (Types.cup expect_rec expect_elt) precise in
let t_elt =
let t = Types.Product.pi2 (Types.Product.get ~kind:`XML t) in
let t = Types.Product.pi1 (Types.Product.get t) in
t in
if not precise then constr
(try Types.Record.project (Types.cup t t_elt) l
with Not_found -> assert false)
| RemoveField (e,l) ->
let t = type_check env e Types.Record.any true in
......@@ -550,6 +550,27 @@ evaluates to
There is another form of projection to extract attributes:
which is equivalent to:
transform %%e%% with <_ l=l>_ -> l
The dot notation can also be used to extract the value of the
attribute for one XML element:
# <a x=3>[].x;;
- : 3 = 3
<section title="Iteration over XML trees">
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment