Add a specific prefix for QNames that represent attributes.
authorKim Nguyễn <kn@lri.fr>
Thu, 14 Feb 2013 16:23:35 +0000 (17:23 +0100)
committerKim Nguyễn <kn@lri.fr>
Mon, 4 Mar 2013 18:00:12 +0000 (19:00 +0100)
Use that prefix in the naive tree implementation for attribute nodes.

src/tree/naive.ml
src/utils/qName.ml
src/utils/qName.mli

index 1086b1e..8654c45 100644 (file)
@@ -14,7 +14,7 @@
 (***********************************************************************)
 
 (*
-  Time-stamp: <Last modified on 2013-02-07 09:59:37 CET by Kim Nguyen>
+  Time-stamp: <Last modified on 2013-02-14 16:14:00 CET by Kim Nguyen>
 *)
 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;
index ca4a5a3..d3f0a43 100644 (file)
@@ -14,7 +14,7 @@
 (***********************************************************************)
 
 (*
-  Time-stamp: <Last modified on 2013-01-30 19:07:38 CET by Kim Nguyen>
+  Time-stamp: <Last modified on 2013-02-14 16:14:44 CET by Kim Nguyen>
 *)
 
 include Hcons.Make (struct
@@ -35,3 +35,10 @@ let comment = of_string "#comment"
 let document_fragment = of_string "#document-fragment"
 let attribute_map = of_string "#attribute-map"
 let nil = of_string "#"
+let attribute_prefix = of_string "@"
+let has_attribute_prefix s =
+  let s = node s in
+  String.length s > 0 && s.[0] = '@'
+
+let add_attribute_prefix s =
+  of_string ("@" ^ (node s))
index 081c24d..4ffaa41 100644 (file)
@@ -14,7 +14,7 @@
 (***********************************************************************)
 
 (*
-  Time-stamp: <Last modified on 2013-01-30 19:07:34 CET by Kim Nguyen>
+  Time-stamp: <Last modified on 2013-02-14 16:15:23 CET by Kim Nguyen>
 *)
 
 (** Implementation of qualified names as hashconsed strings *)
@@ -51,7 +51,7 @@ val cdata_section : t
 
 val comment : t
 (** Represents the QName of a comment node. Equivalent to
-    [of_string "#cdata-section"]
+    [of_string "#comment"]
 *)
 
 val document_fragment : t
@@ -69,3 +69,15 @@ val nil : t
 (** Represents the QName of a nil node. Equivalent to
     [of_string "#"]
 *)
+
+val attribute_prefix : t
+(** Represents a prefix that may be prepended to attribute name
+    to distinguish them from element names
+*)
+
+val has_attribute_prefix : t -> bool
+(** Tests whether the given QName starts with the attribute prefix
+*)
+
+val add_attribute_prefix : t -> t
+(** Prepends the attribute_prefix to the given QName *)