Record which tag ids map to attribute nodes. Use that in subtree_element
[SXSI/XMLTree.git] / xml-tree.cpp
index e230d9b..b33383e 100644 (file)
@@ -98,10 +98,17 @@ xml_tree::xml_tree(std::vector<int32_t> *tags_,
 
   tag_names = new std::vector<std::string>();
   tag_names->resize(tag_ids->size());
-
+  this->attribute_ids = new std::unordered_set<xml_tree::tag_t>();
   std::unordered_map<std::string, tag_t>::iterator val;
-  for(val = this->tag_ids->begin(); val != this->tag_ids->end(); ++val)
+  for(val = this->tag_ids->begin(); val != this->tag_ids->end(); ++val){
     (*tag_names)[val->second] = val->first;
+    if (val->first.size() >= 3 &&
+        val->first[0] == '<' &&
+        val->first[1] == '@' &&
+        val->first[2] == '>'){
+      this->attribute_ids->insert(val->second);
+    };
+  }
 
   uint32_t max_tag = tag_names->size() - 1;
   bit_vector *tmp_bitmap = new bit_vector(npar, 1, 0);
@@ -165,6 +172,7 @@ xml_tree::~xml_tree()
   delete [] tag_seq;
   delete tag_names;
   delete tag_ids;
+  delete attribute_ids;
   if (text_collection) delete text_collection;
   if (text_positions) delete text_positions;
 }
@@ -282,6 +290,7 @@ xml_tree* xml_tree::load(int fd, char* name, bool load_tc, int sf)
   tree->par = loadTree(fp); //TODO use new api
   tree->tag_names = new std::vector<std::string>();
   tree->tag_ids = new std::unordered_map<std::string, xml_tree::tag_t>();
+  tree->attribute_ids = new std::unordered_set<xml_tree::tag_t>();
   std::string s;
   int ntags;
 
@@ -296,6 +305,9 @@ xml_tree* xml_tree::load(int fd, char* name, bool load_tc, int sf)
     tree->tag_names->push_back(s);
     tree->tag_ids->insert(std::make_pair(s,
                                          static_cast<xml_tree::tag_t>(i)));
+    if (s.size() >= 3 && s[0] == '<' && s[1] == '@' && s[2] == '>'){
+      tree->attribute_ids->insert(static_cast<xml_tree::tag_t>(i));
+    };
 
   };