From: Kim Nguyễn Date: Thu, 14 Feb 2013 16:23:35 +0000 (+0100) Subject: Add a specific prefix for QNames that represent attributes. X-Git-Tag: v0.1~176 X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=commitdiff_plain;h=fadcbf2f6f9f33b844fd5e875a1bda4bed446a43 Add a specific prefix for QNames that represent attributes. Use that prefix in the naive tree implementation for attribute nodes. --- diff --git a/src/tree/naive.ml b/src/tree/naive.ml index 1086b1e..8654c45 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; diff --git a/src/utils/qName.ml b/src/utils/qName.ml index ca4a5a3..d3f0a43 100644 --- a/src/utils/qName.ml +++ b/src/utils/qName.ml @@ -14,7 +14,7 @@ (***********************************************************************) (* - Time-stamp: + Time-stamp: *) 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)) diff --git a/src/utils/qName.mli b/src/utils/qName.mli index 081c24d..4ffaa41 100644 --- a/src/utils/qName.mli +++ b/src/utils/qName.mli @@ -14,7 +14,7 @@ (***********************************************************************) (* - Time-stamp: + Time-stamp: *) (** 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 *)