3 // functions to convert tag positions to the corresponding tree node and viceversa.
\r
4 // These are implemented in order to be able to change the tree and Tags representations,
\r
5 // without affecting the code so much.
\r
6 // Current implementation corresponds to balanced-parentheses representation for
\r
7 // the tree, and storing 2 tags per tree node (opening and closing tags).
\r
9 // tag position -> tree node
\r
10 inline treeNode tagpos2node(int t) {
\r
14 // tree node -> tag position
\r
15 inline int node2tagpos(treeNode x) {
\r
19 // Save: saves XML tree data structure to file.
\r
20 void XMLTree::Save(unsigned char *filename)
\r
24 char filenameaux[1024];
\r
27 sprintf(filenameaux, "%s.srx", filename);
\r
28 fp = fopen(filenameaux, "w");
\r
30 printf("Error: cannot create file %s to store the tree structure of XML collection\n", filenameaux);
\r
34 // first stores the tree topology
\r
37 // stores the table with tag names
\r
38 fwrite(&ntagnames, sizeof(int), 1, fp);
\r
39 for (i=0; i<ntagnames;i++)
\r
40 fprintf(fp, "%s\n",TagName[i]);
\r
43 fwrite(&indexing_empty_texts, sizeof(bool), 1, fp);
\r
44 fwrite(&initialized, sizeof(bool), 1, fp);
\r
45 fwrite(&finished, sizeof(bool), 1, fp);
\r
47 if (!indexing_empty_texts) EBVector->save(fp);
\r
52 // stores the texts
\r
60 // Load: loads XML tree data structure from file. Returns
\r
61 // a pointer to the loaded data structure
\r
62 XMLTree *XMLTree::Load(unsigned char *filename, int sample_rate_text)
\r
66 char filenameaux[1024];
\r
70 // first load the tree topology
\r
71 sprintf(filenameaux, "%s.srx", filename);
\r
72 fp = fopen(filenameaux, "r");
\r
74 printf("Error: cannot open file %s to load the tree structure of XML collection\n", filenameaux);
\r
78 XML_Tree = new XMLTree();
\r
80 XML_Tree->Par = (bp *)malloc(sizeof(bp));
\r
82 loadTree(XML_Tree->Par, fp);
\r
84 // stores the table with tag names
\r
85 fread(&XML_Tree->ntagnames, sizeof(int), 1, fp);
\r
87 XML_Tree->TagName = (unsigned char **)malloc(XML_Tree->ntagnames*sizeof(unsigned char *));
\r
89 for (i=0; i<XML_Tree->ntagnames;i++) {
\r
91 fscanf(fp, "%s\n",filenameaux);
\r
92 XML_Tree->TagName[i] = (unsigned char *)malloc(sizeof(unsigned char)*(strlen((const char *)filenameaux)+1));
\r
93 strcpy((char *)XML_Tree->TagName[i], (const char *)filenameaux);
\r
97 fread(&(XML_Tree->indexing_empty_texts), sizeof(bool), 1, fp);
\r
98 fread(&(XML_Tree->initialized), sizeof(bool), 1, fp);
\r
99 fread(&(XML_Tree->finished), sizeof(bool), 1, fp);
\r
101 if (!(XML_Tree->indexing_empty_texts)) XML_Tree->EBVector = static_bitsequence_rrr02::load(fp);
\r
104 XML_Tree->Tags = static_sequence::load(fp);
\r
106 // loads the texts
\r
107 XML_Tree->Text->Load(fp,sample_rate_text);
\r
115 // ~XMLTree: frees memory of XML tree.
\r
116 XMLTree::~XMLTree()
\r
121 free(Par); // frees the memory of struct Par
\r
123 for (i=0; i<ntagnames;i++)
\r
128 if (!indexing_empty_texts) {
\r
129 //EBVector->~static_bitsequence_rrr02();
\r
134 //Tags->~static_sequence_wvtree();
\r
138 //Text->~TextCollection();
\r
142 initialized = false;
\r
146 // root(): returns the tree root.
\r
147 treeNode XMLTree::Root()
\r
150 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
153 return root_node(Par);
\r
156 // SubtreeSize(x): the number of nodes (and attributes) in the subtree of node x.
\r
157 int XMLTree::SubtreeSize(treeNode x)
\r
160 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
163 return subtree_size(Par, x);
\r
166 // SubtreeTags(x,tag): the number of occurrences of tag within the subtree of node x.
\r
167 int XMLTree::SubtreeTags(treeNode x, TagType tag)
\r
170 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
174 int s = x + 2*subtree_size(Par, x) - 1;
\r
176 return Tags->rank(tag, s) - Tags->rank(tag, node2tagpos(x)-1);
\r
179 // IsLeaf(x): returns whether node x is leaf or not. In the succinct representation
\r
180 // this is just a bit inspection.
\r
181 bool XMLTree::IsLeaf(treeNode x)
\r
183 return isleaf(Par, x);
\r
186 // IsAncestor(x,y): returns whether node x is ancestor of node y.
\r
187 bool XMLTree::IsAncestor(treeNode x, treeNode y)
\r
190 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
194 return is_ancestor(Par, x, y);
\r
197 // IsChild(x,y): returns whether node x is parent of node y.
\r
198 bool XMLTree::IsChild(treeNode x, treeNode y)
\r
201 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
205 if (!is_ancestor(Par, x, y)) return false;
\r
206 return depth(Par, x) == (depth(Par, y) + 1);
\r
209 // NumChildren(x): number of children of node x. Constant time with the data structure
\r
211 int XMLTree::NumChildren(treeNode x)
\r
214 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
218 return degree(Par, x);
\r
221 // ChildNumber(x): returns i if node x is the i-th children of its parent.
\r
222 int XMLTree::ChildNumber(treeNode x)
\r
225 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
229 return child_rank(Par, x);
\r
232 // Depth(x): depth of node x, a simple binary rank on the parentheses sequence.
\r
233 int XMLTree::Depth(treeNode x)
\r
236 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
240 return depth(Par, x);
\r
243 // Preorder(x): returns the preorder number of node x, just counting the tree
\r
244 // nodes (i.e., tags, it disregards the texts in the tree).
\r
245 int XMLTree::Preorder(treeNode x)
\r
248 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
252 return preorder_rank(Par, x);
\r
255 // Postorder(x): returns the postorder number of node x, just counting the tree
\r
256 // nodes (i.e., tags, it disregards the texts in the tree).
\r
257 int XMLTree::Postorder(treeNode x)
\r
260 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
264 return postorder_rank(Par, x);
\r
267 // Tag(x): returns the tag identifier of node x.
\r
268 TagType XMLTree::Tag(treeNode x)
\r
271 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
275 return Tags->access(node2tagpos(x));
\r
278 // DocIds(x): returns the range of text identifiers that descend from node x.
\r
279 // returns {NULLT, NULLT} when there are no texts descending from x.
\r
280 range XMLTree::DocIds(treeNode x)
\r
283 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
288 if (indexing_empty_texts) { // faster, no rank needed
\r
290 r.max = x+2*subtree_size(Par, x)-2;
\r
292 else { // we are not indexing empty texts, we need rank
\r
293 int min = EBVector->rank1(x-1);
\r
294 int max = EBVector->rank1(x+2*subtree_size(Par, x)-2);
\r
295 if (min==max) { // range is empty, no texts within the subtree of x
\r
299 else { // the range is non-empty, there are texts within the subtree of x
\r
307 // Parent(x): returns the parent node of node x.
\r
308 treeNode XMLTree::Parent(treeNode x)
\r
311 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
315 return parent(Par, x);
\r
318 // Child(x,i): returns the i-th child of node x, assuming it exists.
\r
319 treeNode XMLTree::Child(treeNode x, int i)
\r
322 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
326 if (i <= OPTD) return naive_child(Par, x, i);
\r
327 else return child(Par, x, i);
\r
330 // FirstChild(x): returns the first child of node x, assuming it exists. Very fast in BP.
\r
331 treeNode XMLTree::FirstChild(treeNode x)
\r
334 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
338 return first_child(Par, x);
\r
341 // NextSibling(x): returns the next sibling of node x, assuming it exists.
\r
342 treeNode XMLTree::NextSibling(treeNode x)
\r
345 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
351 return next_sibling(Par, x);
\r
354 // PrevSibling(x): returns the previous sibling of node x, assuming it exists.
\r
355 treeNode XMLTree::PrevSibling(treeNode x)
\r
358 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
362 return prev_sibling(Par, x);
\r
365 // TaggedChild(x,i,tag): returns the i-th child of node x tagged tag, or NULLT if there is none.
\r
366 // Because of the balanced-parentheses representation of the tree, this operation is not supported
\r
367 // efficiently, just iterating among the children of node x until finding the desired child.
\r
368 treeNode XMLTree::TaggedChild(treeNode x, int i, TagType tag)
\r
371 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
377 child = first_child(Par, x); // starts at first child of node x
\r
378 if (child==(treeNode)-1) return NULLT; // node x is a leaf, there is no such child
\r
379 while (child!=(treeNode)-1) {
\r
380 if (Tags->access(node2tagpos(child)) == tag) { // current child is labeled with tag of interest
\r
382 if (i==0) return child; // we have seen i children of x tagged tag, this is the one we are looking for
\r
384 child = next_sibling(Par, x); // OK, let's try with the next child
\r
386 return NULLT; // no such child was found
\r
389 // TaggedDesc(x,tag): returns the first node tagged tag with larger preorder than x and within
\r
390 // the subtree of x. Returns NULLT if there is none.
\r
391 treeNode XMLTree::TaggedDesc(treeNode x, TagType tag)
\r
394 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
400 r = (int) Tags->rank(tag, node2tagpos(x));
\r
401 s = (int) Tags->select(tag, r+1);
\r
402 if (s == -1) return NULLT; // there is no such node
\r
403 y = tagpos2node(s); // transforms the tag position into a node position
\r
404 if (!is_ancestor(Par, x, y)) return NULLT; // the next node tagged tag (in preorder) is not within the subtree of x.
\r
408 // TaggedPrec(x,tag): returns the first node tagged tag with smaller preorder than x and not an
\r
409 // ancestor of x. Returns NULLT if there is none.
\r
410 treeNode XMLTree::TaggedPrec(treeNode x, TagType tag)
\r
413 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
418 treeNode node_s, root;
\r
419 r = (int)Tags->rank(tag, node2tagpos(x)-1);
\r
420 if (r==0) return NULLT; // there is no such node.
\r
421 s = (int)Tags->select(tag, r);
\r
422 root = root_node(Par);
\r
423 node_s = tagpos2node(s);
\r
424 while (is_ancestor(Par, node_s, x) && (node_s!=root)) { // the one that we found is an ancestor of x
\r
426 if (r==0) return NULLT; // there is no such node
\r
427 s = (int)Tags->select(tag, r); // we should use select_prev instead when provided
\r
428 node_s = tagpos2node(s);
\r
430 return NULLT; // there is no such node
\r
433 // TaggedFoll(x,tag): returns the first node tagged tag with larger preorder than x and not in
\r
434 // the subtree of x. Returns NULLT if there is none.
\r
435 treeNode XMLTree::TaggedFoll(treeNode x, TagType tag)
\r
438 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
443 r = (int) Tags->rank(tag, node2tagpos(next_sibling(Par, x))-1);
\r
444 s = (int) Tags->select(tag, r+1); // select returns -1 in case that there is no r+1-th tag.
\r
445 if (s==-1) return NULLT;
\r
446 else return tagpos2node(s);
\r
449 // PrevText(x): returns the document identifier of the text to the left
\r
450 // of node x, or NULLT if x is the root node or the text is empty.
\r
451 // Assumes Doc ids start from 0.
\r
452 DocID XMLTree::PrevText(treeNode x)
\r
455 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
459 if (x == Root()) return NULLT;
\r
460 if (indexing_empty_texts) // faster, no rank needed
\r
462 else { // we are not indexing empty texts, rank is needed
\r
463 if (EBVector->access(x-1) == 0)
\r
464 return (DocID)NULLT; // there is no text to the left of node (text is empty)
\r
466 return (DocID)EBVector->rank1(x-1)-1; //-1 because document ids start from 0
\r
470 // NextText(x): returns the document identifier of the text to the right
\r
471 // of node x, or NULLT if x is the root node. Assumes Doc ids start from 0.
\r
472 DocID XMLTree::NextText(treeNode x)
\r
475 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
479 if (x == Root()) return NULLT;
\r
480 if (indexing_empty_texts) // faster, no rank needed
\r
481 return (DocID)x+2*subtree_size(Par, x)-1;
\r
482 else { // we are not indexing empty texts, rank is needed
\r
483 int p = x+2*subtree_size(Par, x)-1;
\r
484 if (EBVector->access(p) == 0) // there is no text to the right of node
\r
485 return (DocID)NULLT;
\r
487 return (DocID)EBVector->rank1(p)-1; //-1 because document ids start from 0
\r
491 // MyText(x): returns the document identifier of the text below node x,
\r
492 // or NULLT if x is not a leaf node or the text is empty. Assumes Doc
\r
493 // ids start from 0.
\r
494 DocID XMLTree::MyText(treeNode x)
\r
497 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
501 if (!IsLeaf(x)) return NULLT;
\r
502 if (indexing_empty_texts) // faster, no rank needed
\r
504 else { // we are not indexing empty texts, rank is needed
\r
505 if (EBVector->access(x) == 0) // there is no text below node x
\r
506 return (DocID)NULLT;
\r
508 return (DocID)EBVector->rank1(x)-1; //-1 because document ids start from 0
\r
512 // TextXMLId(d): returns the preorder of document with identifier d in the tree consisting of
\r
513 // all tree nodes and all text nodes. Assumes that the tree root has preorder 1.
\r
514 int XMLTree::TextXMLId(DocID d)
\r
517 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
521 if (indexing_empty_texts)
\r
522 return d + rank_open(Par, d)+1; // +1 because root has preorder 1
\r
523 else { // slower, needs rank and select
\r
524 int s = EBVector->select1(d+1);
\r
525 return rank_open(Par, s) + d + 1; // +1 because root has preorder 1
\r
529 // NodeXMLId(x): returns the preorder of node x in the tree consisting
\r
530 // of all tree nodes and all text nodes. Assumes that the tree root has
\r
532 int XMLTree::NodeXMLId(treeNode x)
\r
535 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
539 if (indexing_empty_texts)
\r
540 return x - 1 + rank_open(Par, x);
\r
542 if (x == Root()) return 1; // root node has preorder 1
\r
544 return rank_open(Par, x) + EBVector->rank1(x-1);
\r
548 // ParentNode(d): returns the parent node of document identifier d.
\r
549 treeNode XMLTree::ParentNode(DocID d)
\r
552 fprintf(stderr, "Error: data structure has not been constructed properly\n");
\r
557 if (indexing_empty_texts) s = d;
\r
558 else s = EBVector->select1(d);
\r
560 if (inspect(Par,s) == CP) // is a closing parenthesis
\r
561 return parent(Par, find_open(Par, s));
\r
562 else // is an opening parenthesis
\r
563 return (treeNode)s;
\r
568 // OpenDocument(empty_texts): it starts the construction of the data structure for
\r
569 // the XML document. Parameter empty_texts indicates whether we index empty texts
\r
570 // in document or not. Returns a non-zero value upon success, NULLT in case of error.
\r
571 int XMLTree::OpenDocument(bool empty_texts, int sample_rate_text)
\r
573 initialized = true;
\r
579 indexing_empty_texts = empty_texts;
\r
581 par_aux = (pb *)malloc(sizeof(pb)*parArraySize);
\r
583 fprintf(stderr, "Error: not enough memory\n");
\r
587 tags_aux = (TagType *) malloc(sizeof(TagType));
\r
589 fprintf(stderr, "Error: not enough memory\n");
\r
595 if (!indexing_empty_texts) {
\r
596 empty_texts_aux = (unsigned int *)malloc(sizeof(unsigned int));
\r
597 if (!empty_texts_aux) {
\r
598 fprintf(stderr, "Error: not enough memory\n");
\r
603 Text = TextCollection::InitTextCollection((unsigned)sample_rate_text);
\r
605 return 1; // indicates success in the initialization of the data structure
\r
608 // CloseDocument(): it finishes the construction of the data structure for the XML
\r
609 // document. Tree and tags are represented in the final form, dynamic data
\r
610 // structures are made static, and the flag "finished" is set to true. After that,
\r
611 // the data structure can be queried.
\r
612 int XMLTree::CloseDocument()
\r
614 if (!initialized) { // data structure has not been initialized properly
\r
615 fprintf(stderr, "Error: data structure has not been initialized properly (by calling method OpenDocument)\n");
\r
619 // closing parenthesis for the tree root
\r
620 par_aux = (pb *)realloc(par_aux, sizeof(pb)*(1+npar/(8*sizeof(pb))));
\r
622 fprintf(stderr, "Error: not enough memory\n");
\r
626 // creates the data structure for the tree topology
\r
627 Par = (bp *)malloc(sizeof(bp));
\r
628 bp_construct(Par, npar, par_aux, OPT_DEGREE|0);
\r
629 // creates structure for tags
\r
630 static_bitsequence_builder * bmb = new static_bitsequence_builder_brw32(20);
\r
631 static_permutation_builder * pmb = new static_permutation_builder_mrrr(PERM_SAMPLE, bmb);
\r
632 static_sequence_builder * ssb = new static_sequence_builder_gmr_chunk(bmb, pmb);
\r
634 Tags = new static_sequence_gmr((uint *) tags_aux, (uint) npar-1,2*ntagnames, bmb, ssb);
\r
639 // makes the text collection static
\r
640 Text->MakeStatic();
\r
642 // creates the data structure marking the non-empty texts (just in the case it is necessary)
\r
643 if (!indexing_empty_texts)
\r
644 EBVector = new static_bitsequence_rrr02((uint *)empty_texts_aux,(ulong)npar,(uint)32);
\r
648 return 1; // indicates success in the inicialization
\r
652 // NewOpenTag(tagname): indicates the event of finding a new opening tag in the document.
\r
653 // Tag name is given. Returns a non-zero value upon success, and returns NULLT
\r
654 // in case of failing when trying to insert the new tag.
\r
655 int XMLTree::NewOpenTag(unsigned char *tagname)
\r
659 if (!initialized) { // data structure has not been initialized properly
\r
660 fprintf(stderr, "Error: you cannot insert a new opening tag without first calling method OpenDocument first\n");
\r
664 // inserts a new opening parentheses in the bit sequence
\r
665 if (sizeof(pb)*8*parArraySize == npar) { // no space left for the new parenthesis
\r
666 par_aux = (pb *)realloc(par_aux, sizeof(pb)*2*parArraySize);
\r
671 fprintf(stderr, "Error: not enough memory\n");
\r
675 setbit(par_aux,npar,OP); // marks a new opening parenthesis
\r
677 // transforms the tagname into a tag identifier. If the tag is new, we insert
\r
678 // it in the table.
\r
679 for (i=0; i<ntagnames; i++)
\r
680 if (strcmp((const char *)tagname,(const char *)TagName[i])==0) break;
\r
682 if (i==ntagnames) { // the tag is a new one, then we insert it
\r
683 TagName = (unsigned char **)realloc(TagName, sizeof(char *)*(ntagnames+1));
\r
686 fprintf(stderr, "Error: not enough memory\n");
\r
691 TagName[i] = (unsigned char *)malloc(sizeof(unsigned char)*(strlen((const char *)tagname)+1));
\r
692 strcpy((char *)TagName[i], (const char *)tagname);
\r
694 tags_aux = (TagType *) realloc(tags_aux, sizeof(TagType)*(npar + 1));
\r
696 fprintf(stderr, "Error: not enough memory\n");
\r
700 tags_aux[npar] = i; // inserts the new tag id within the preorder sequence of tags
\r
709 // NewClosingTag(tagname): indicates the event of finding a new closing tag in the document.
\r
710 // Tag name is given. Returns a non-zero value upon success, and returns NULLT
\r
711 // in case of failing when trying to insert the new tag.
\r
712 int XMLTree::NewClosingTag(unsigned char *tagname)
\r
716 if (!initialized) { // data structure has not been initialized properly
\r
717 fprintf(stderr, "Error: you cannot insert a new closing tag without first calling method OpenDocument first\n");
\r
721 // inserts a new closing parentheses in the bit sequence
\r
722 if (sizeof(pb)*8*parArraySize == npar) { // no space left for the new parenthesis
\r
723 par_aux = (pb *)realloc(par_aux, sizeof(pb)*2*parArraySize);
\r
728 fprintf(stderr, "Error: not enough memory\n");
\r
731 setbit(par_aux,npar,CP); // marks a new closing opening parenthesis
\r
733 // transforms the tagname into a tag identifier. If the tag is new, we insert
\r
734 // it in the table.
\r
735 for (i=0; i<ntagnames; i++)
\r
736 if (strcmp((const char *)tagname,(const char *)TagName[i])==0) break;
\r
738 if (i==ntagnames) { // the tag is a new one, then we insert it
\r
739 TagName = (unsigned char **)realloc(TagName, sizeof(char *)*(ntagnames+1));
\r
742 fprintf(stderr, "Error: not enough memory\n");
\r
747 TagName[i] = (unsigned char *)malloc(sizeof(char)*(strlen((const char *)tagname)+2));
\r
748 TagName[i][0] = '/';
\r
749 strcpy((char *)&(TagName[i][1]), (const char *)tagname);
\r
752 tags_aux = (TagType *)realloc(tags_aux, sizeof(TagType)*(npar + 1));
\r
755 fprintf(stderr, "Error: not enough memory\n");
\r
759 tags_aux[npar] = i; // inserts the new tag id within the preorder sequence of tags
\r
763 return 1; // success
\r
768 // NewText(s): indicates the event of finding a new (non-empty) text s in the document.
\r
769 // The new text is inserted within the text collection. Returns a non-zero value upon
\r
770 // success, NULLT in case of error.
\r
771 int XMLTree::NewText(unsigned char *s)
\r
773 if (!initialized) { // data structure has not been initialized properly
\r
774 fprintf(stderr, "Error: you cannot insert a new text without first calling method OpenDocument first\n");
\r
778 if (!indexing_empty_texts) {
\r
779 empty_texts_aux = (unsigned int *)realloc(empty_texts_aux, sizeof(pb)*(1+(npar-1)/(8*sizeof(pb))));
\r
780 if (!empty_texts_aux) {
\r
781 fprintf(stderr, "Error: not enough memory\n");
\r
785 bitset(empty_texts_aux, npar-1); // marks the non-empty text with a 1 in the bit vector
\r
788 Text->InsertText(s);
\r
790 return 1; // success
\r
793 // NewEmptyText(): indicates the event of finding a new empty text in the document.
\r
794 // In case of indexing empty and non-empty texts, we insert the empty texts into the
\r
795 // text collection. In case of indexing only non-empty texts, it just indicates an
\r
796 // empty text in the bit vector of empty texts. Returns a non-zero value upon
\r
797 // success, NULLT in case of error.
\r
798 int XMLTree::NewEmptyText()
\r
800 unsigned char c = 0;
\r
801 if (!initialized) { // data structure has not been initialized properly
\r
802 fprintf(stderr, "Error: you cannot insert a new empty text without first calling method OpenDocument first\n");
\r
806 if (!indexing_empty_texts) {
\r
807 empty_texts_aux = (unsigned int *)realloc(empty_texts_aux, sizeof(pb)*(1+(npar-1)/(8*sizeof(pb))));
\r
808 if (!empty_texts_aux) {
\r
809 fprintf(stderr, "Error: not enough memory\n");
\r
813 bitclean(empty_texts_aux, npar-1); // marks the empty text with a 0 in the bit vector
\r
815 else Text->InsertText(&c); // we insert the empty text just in case we index all the texts
\r
817 return 1; // success
\r
821 // GetTagId: returns the tag identifier corresponding to a given tag name.
\r
822 // Returns NULLT in case that the tag name does not exists.
\r
823 TagType XMLTree::GetTagId(unsigned char *tagname)
\r
826 // this should be changed for more efficient processing
\r
827 for (i=0; i<ntagnames; i++)
\r
828 if (strcmp((const char *)tagname,(const char *)TagName[i])==0) break;
\r
829 if (i==ntagnames) return (TagType)NULLT; // tagname does not exists in the table
\r
834 // GetTagName(tagid): returns the tag name of a given tag identifier.
\r
835 // Returns NULL in case that the tag identifier is not valid.
\r
836 unsigned char *XMLTree::GetTagName(TagType tagid)
\r
840 if (tagid >= ntagnames) return NULL; // invalid tag identifier
\r
841 s = (unsigned char *)malloc((strlen((const char *)TagName[tagid])+1)*sizeof(unsigned char));
\r
842 strcpy((char *)s, (const char *)TagName[tagid]);
\r