X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Ftree%2Fnaive.ml;h=cff6ee2019dc329ffba874ae0ec32e3784f82414;hb=f749a3e33d759fddef63a69e54ff1336411d5e16;hp=1086b1e793564a3dc9219f3fd4fe2f811321b64a;hpb=30bc0bb1291426e5e26eb2dee1ffc41e4c246349;p=tatoo.git diff --git a/src/tree/naive.ml b/src/tree/naive.ml index 1086b1e..cff6ee2 100644 --- a/src/tree/naive.ml +++ b/src/tree/naive.ml @@ -14,7 +14,7 @@ (***********************************************************************) (* - Time-stamp: + Time-stamp: *) open Utils @@ -108,6 +108,7 @@ struct let text_string = QName.to_string QName.text let attr_map_string = QName.to_string QName.attribute_map + let att_pref = QName.node QName.attribute_prefix let rec start_element_handler parser_ ctx tag attr_list = do_text parser_ ctx; let parent = top ctx in @@ -130,7 +131,7 @@ struct end_element_handler parser_ ctx attr_map_string and do_attribute parser_ ctx (att, value) = - let att_tag = " " ^ att in + 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; @@ -227,7 +228,9 @@ let output_escape_string out s = let rec print_attributes out tree_ node = if node != nil then begin - output_string out (QName.to_string node.tag); + let ntag = QName.to_string node.tag in + output_char out ' '; + output out ntag 1 (String.length ntag - 1); output_string out "=\""; output_escape_string out node.first_child.data; output_char out '"'; @@ -236,32 +239,30 @@ let rec print_attributes out tree_ node = let rec print_xml out tree_ node = if node != nil then - let () = - if node.tag == QName.text then - output_escape_string out node.data + let () = + if node.tag == QName.text then + output_escape_string out node.data + else + 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 - 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 - if fchild == nil then output_string out "/>" - else begin - output_char out '>'; - print_xml out tree_ fchild; - output_string out "' - end + node.first_child in - print_xml out tree_ node.next_sibling + if fchild == nil then output_string out "/>" + else begin + output_char out '>'; + print_xml out tree_ fchild; + output_string out "' + end + in + print_xml out tree_ node.next_sibling let root t = t.root