3e98c8bb3e5a0130c03a0b76afe5738833903b43
[SXSI/xpathcomp.git] / testXMLTree.cpp
1 #include "XMLDocShredder.h"
2 #include "XMLTree.h"
3 #include "Utils.h"
4
5
6 void print_structure(XMLTree* tree, treeNode x){
7   DocID text;
8   if (x != NULLT){
9     std::cout << "Par idx: " << x << ", preorder: " << 
10       tree->NodeXMLId(x) << ", tag='" << tree->GetTagName(tree->Tag(x)) 
11               << "'\n";
12     text = tree->PrevText(x);
13     std::cout << "PrevText(" << x << ")=  " << text
14               << ", value='" << ((text == NULLT) ? "" : (const char*)tree->GetText(text))      
15               << "'\n";
16     text = tree->MyText(x);
17     std::cout << "MyText(" << x << ")=  " << text
18               << ", value='" << ((text == NULLT) ? "" : (const char*)tree->GetText(text))      
19               << "'\n";
20     text = tree->NextText(x);
21     std::cout << "NextText(" << x << ")=  " << text
22               << ", value='" << ((text == NULLT) ? "" : (const char*)tree->GetText(text))      
23               << "'\n";
24     print_structure(tree,tree->FirstChild(x));
25     print_structure(tree,tree->NextSibling(x));            
26   };
27 }
28
29 int main(int argc, char** argv){
30   XMLTree * tree;
31   if (argc != 2){
32     std::cout << "Usage " << argv[0] << " filename.xml" << std::endl;
33     return 1;
34   };
35
36   XMLDocShredder shredder(argv[1],64,false,false);
37   shredder.processStartDocument("");
38   shredder.parse();
39   shredder.processEndDocument();
40   tree = (XMLTree *) shredder.storageIfc_->returnDocument();
41   print_structure(tree,tree->Root());
42   return 0;
43 }