projects
/
tatoo.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix the handling of attributes:
[tatoo.git]
/
src
/
tree
/
naive.ml
diff --git
a/src/tree/naive.ml
b/src/tree/naive.ml
index
db1b202
..
ee93863
100644
(file)
--- a/
src/tree/naive.ml
+++ b/
src/tree/naive.ml
@@
-14,7
+14,7
@@
(***********************************************************************)
(*
(***********************************************************************)
(*
- Time-stamp: <Last modified on 2013-03-0
5 16:20:32
CET by Kim Nguyen>
+ Time-stamp: <Last modified on 2013-03-0
9 18:49:04
CET by Kim Nguyen>
*)
open Utils
*)
open Utils
@@
-123,19
+123,12
@@
struct
if parent.first_child == dummy then parent.first_child <- n
else parent.next_sibling <- n;
push n ctx;
if parent.first_child == dummy then parent.first_child <- n
else parent.next_sibling <- n;
push n ctx;
- match attr_list with
- [] -> ()
- | _ ->
- start_element_handler parser_ ctx attr_map_string [];
- List.iter (do_attribute parser_ ctx) attr_list;
- end_element_handler parser_ ctx attr_map_string
+ List.iter (do_attribute parser_ ctx) attr_list
and do_attribute parser_ ctx (att, value) =
let att_tag = att_pref ^ att in
start_element_handler parser_ ctx att_tag [];
and do_attribute parser_ ctx (att, value) =
let att_tag = att_pref ^ att in
start_element_handler parser_ ctx att_tag [];
- start_element_handler parser_ ctx text_string [];
let n = top ctx in n.data <- value;
let n = top ctx in n.data <- value;
- end_element_handler parser_ ctx text_string;
end_element_handler parser_ ctx att_tag
and consume_closing ctx n =
end_element_handler parser_ ctx att_tag
and consume_closing ctx n =
@@
-226,16
+219,19
@@
let output_escape_string out s =
| c -> output_char out c
done
| c -> output_char out c
done
-let rec print_attributes out tree_ node =
- if node != nil then begin
- let ntag = QName.to_string node.tag in
- output_char out ' ';
+let rec print_attributes ?(sep=true) out tree_ node =
+ let tag = node.tag in
+ if QName.has_attribute_prefix tag then begin
+ let ntag = QName.node tag in
+ if sep then output_char out ' ';
output out ntag 1 (String.length ntag - 1);
output_string out "=\"";
output out ntag 1 (String.length ntag - 1);
output_string out "=\"";
- output_escape_string out node.
first_child.
data;
+ output_escape_string out node.data;
output_char out '"';
print_attributes out tree_ node.next_sibling
output_char out '"';
print_attributes out tree_ node.next_sibling
- end
+ end
+ else
+ node
let rec print_xml out tree_ node =
if node != nil then
let rec print_xml out tree_ node =
if node != nil then
@@
-246,13
+242,7
@@
let rec print_xml out tree_ node =
let tag = QName.to_string node.tag in
output_char out '<';
output_string out tag;
let tag = QName.to_string node.tag in
output_char out '<';
output_string out tag;
- let fchild =
- if node.first_child.tag == QName.attribute_map then
- let () = print_attributes out tree_ node.first_child.first_child in
- node.first_child.next_sibling
- else
- node.first_child
- in
+ let fchild = print_attributes out tree_ node.first_child in
if fchild == nil then output_string out "/>"
else begin
output_char out '>';
if fchild == nil then output_string out "/>"
else begin
output_char out '>';
@@
-264,7
+254,13
@@
let rec print_xml out tree_ node =
in
print_xml out tree_ node.next_sibling
in
print_xml out tree_ node.next_sibling
-let print_xml out tree_ node = print_xml out tree_ { node with next_sibling = nil }
+let print_xml out tree_ node =
+ let nnode = { node with next_sibling = nil } in
+ if QName.has_attribute_prefix nnode.tag then
+ ignore (print_attributes ~sep:false out tree_ nnode)
+ else
+ print_xml out tree_ nnode
+
let root t = t.root
let first_child _ n = n.first_child
let next_sibling _ n = n.next_sibling
let root t = t.root
let first_child _ n = n.first_child
let next_sibling _ n = n.next_sibling