X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftree%2Fnaive.ml;h=db1b202f1666318cf6ef932941314979ce7e83e2;hb=54d24e939b72601a55832aa447ed31f1b256f02e;hp=8654c450e29ca4eec05c17bcb3b3552e930e5b15;hpb=fadcbf2f6f9f33b844fd5e875a1bda4bed446a43;p=tatoo.git diff --git a/src/tree/naive.ml b/src/tree/naive.ml index 8654c45..db1b202 100644 --- a/src/tree/naive.ml +++ b/src/tree/naive.ml @@ -14,7 +14,7 @@ (***********************************************************************) (* - Time-stamp: + Time-stamp: *) open Utils @@ -72,7 +72,7 @@ struct "NODE " ^ string_of_int n.preorder) let debug_node fmt node = - Format.fprintf fmt "{ tag=%s; preorder=%i; data=%s; first_child=%a; next_sibling=%a; parent=%a }" + Format.fprintf fmt "{ tag=%s; preorder=%i; data=%S; first_child=%a; next_sibling=%a; parent=%a }" (QName.to_string node.tag) node.preorder node.data @@ -142,7 +142,7 @@ struct if n.next_sibling != dummy then let _ = pop ctx in consume_closing ctx (top ctx) - and end_element_handler parser_ ctx tag = + and end_element_handler parser_ ctx _ = do_text parser_ ctx; let node = top ctx in if node.first_child == dummy then node.first_child <- nil @@ -162,7 +162,7 @@ struct - let character_data_handler parser_ ctx text = + let character_data_handler _parser ctx text = Buffer.add_string ctx.text_buffer text let create_parser () = @@ -228,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 '"'; @@ -237,34 +239,32 @@ 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 print_xml out tree_ node = print_xml out tree_ { node with next_sibling = nil } let root t = t.root let first_child _ n = n.first_child let next_sibling _ n = n.next_sibling @@ -272,3 +272,5 @@ let parent _ n = n.parent let tag _ n = n.tag let data _ n = n.data let preorder _ n = n.preorder + +let print_node fmt n = Parser.debug_node fmt n