[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/01/2009 at 11:25PM PST, ID: 24862961
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

4.2

insert (2)

Asked by valleytech in C++ Programming Language

I am implementing alex idea. I am having little bug here. in parseXMLNode, i can't get the return value from readCurrentXmlTag() .
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
#include <stdio.h>
#include <string>
#include <vector>
#include <fstream>
 
#include <iostream>
using namespace std;
 
 
struct TreeNode
{
    std::string key;
    std::vector<TreeNode> children;
};
 
class Tree
{
    // the one and only root node
    TreeNode root;
    ifstream fin; 
    char holder[100];
    string beforePreviousCurrentTag;// help to solve tag case: /branch ->branch->attribute
 
public:  
    bool    ignoreStartTags();
    bool    parseXML();
    void    draw();
 
private:
    void    parseXMLNode(TreeNode &parentNode);
    string  readCurrentXmlTag();
    string  readCurrentXmlKey(string tag); 
    void    drawNode(TreeNode & parentNode, int indent);
};
 
 
string Tree:: readCurrentXmlKey(string tag)
{
    string key;
    char array[100];
    int counter = 0; 
 
    if( tag == "branch" || tag == "leaf")
    {
        counter = 3;
    }
    else if(tag =="attribute") //recusive function : tag is attribute... case
    {
        counter = 2;
    }
 
    if( !fin.eof())
    {
        for(int i = 0; i < counter; i ++)
        {
            if(tag == "attribute" && beforePreviousCurrentTag == "/branch")
            {
                printf("holder is :%s\n",holder);
                strcpy(array,holder); 
                strcpy(holder,"\0"); //reset content
                beforePreviousCurrentTag ="";// reset  
                cout<<"***special case ***"<<endl;
            }
            else
            {
                fin.getline(array,100);
            } 
            cout<<"XmlKey-> read line : "<<array<<endl;
 
            if( i == 0)
            {
                char * pch;
                char delims[]= "=\"" ;           //"<=\">"; //get " must use \" to distingusih between newline and " 
 
                pch = strtok(array,delims);
              //  printf("1st~~~~~%s\n",pch);
                while(pch != NULL)
                {
                    if( strcmp(pch,"latin_name") ==0 ) 
                    {
                        pch = strtok(NULL,delims);
                      //  printf("2nd~~~~~%s\n",pch);
                        pch = strtok(NULL,delims);
                      //  printf("3rd~~~~~%s\n",pch);  
 
                        key = pch;
                        //cout<<Value<<endl;
                        break;
                    }
                    pch = strtok(NULL,delims);
 
                }//end of  strtok while
            }// end of if counter == 0
        }//end of for
        cout<<"key is :"<<key<<endl;
 
    }// end of file    
    return key;
} 
bool Tree::ignoreStartTags()
{
    char array[1000]; 
    fin.open("Treeinput.txt",ios_base::in); 
    if (!fin) 
    {
        cout << "Fail to open file!!!."<< endl;
        return false;
    }
    else
    {
        // just ignore the first 8 lines
        for( int i = 0; i< 8; i++)
        {
            fin.getline(array,100);
        }
        return true;
    } 
} 
 
 
void Tree::drawNode ( TreeNode &parentNode, int indent)
{
    int i=0,j=0;
    indent ++;
     
    for( j =0; j <indent; j++)
    {
        cout<<"+";
    } 
    cout<<"\""<<parentNode.key<<"\""<<"  "<<endl;
    
    if( parentNode.children.size()== 0)
    {
        return;
    }
    else
    {
        for(int i = 0; i <parentNode.children.size();i++)
        {
            drawNode(parentNode.children[i],indent);
        }
    }
}
 
 
void Tree::draw()
{
    int indent = 0;
    cout<<endl<<"start display tree"<<endl;
    drawNode(root,indent);
}
 
bool Tree::parseXML() 
{
    string tag;
   //here in that function we put the loop you now have at begin of parseXMLNode
   //in case of read errors or missin g tags it return false
    
    if( !ignoreStartTags()) return false; 
    tag = readCurrentXmlTag(); 
    // read root key
    string key = readCurrentXmlKey(tag); 
    if( key.empty()) return false;
    root.key =key; 
    // now the root node is complete like any other parent node...
    parseXMLNode(root);
    return true;
} 
string Tree::readCurrentXmlTag()
{
    string Tag;
    char array[100];
    
    if( !fin.eof())
    {
        fin.getline(array,100);
        cout<<endl<<"XmlTag-> read line : "<<array<<endl; 
        char tmp[100];
        strcpy(tmp,array);
 
        char * pch;
        char delims[]= "< >" ;          
 
        pch = strtok(array,delims);
        while(pch != NULL)
        {
            if( strcmp(pch,"branch")==0 || strcmp (pch,"/branch")== 0||
                strcmp(pch,"leaf")== 0 || strcmp (pch,"/leaf")== 0 || strcmp(pch,"attribute") == 0)
            {
              /*
                if(strcmp(pch,"attribute")== 0 && beforePreviousCurrentTag == "/branch" )
                {
                    strcpy(holder,tmp);
                    printf("holder is %s\n",holder);
                }*/ 
                Tag = pch;
                
                break;
            }
            pch = strtok(NULL,delims);
 
        }//end of  strtok while
        
        if(Tag =="/branch")
        {
           // beforePreviousCurrentTag = Tag;
            cout<<"--->Tag is /branch"<<endl;
        } 
        cout<<"before return, Tag : "<<Tag<<endl;
        return Tag;
    }
    else
    {
        fin.close();
        exit(1);
    }  
}
void Tree::parseXMLNode( TreeNode &parentNode)
{
    cout<<"Beginning of parseXMLNode"<<endl; 
    string tag;
    string key;
    TreeNode child; 
    tag = readCurrentXmlTag();
    cout<<"tag is : "<<endl;  //?????????????? 
    while(  tag != "/branch")
    {
        key = readCurrentXmlKey(tag);
    
        child.key = key;
        parentNode.children.push_back(child);
      
        if(tag == "branch")
        {
            TreeNode &childRef = parentNode.children.back(); 
            draw();
            cout<<"childRef key is "<<childRef.key<<endl;
            parseXMLNode(childRef);
        }
        else if( tag =="leaf")
        {
            draw();
            parseXMLNode(parentNode);
            tag == readCurrentXmlTag();
            if(tag == "/leaf")
            {
                continue;
            }
        }
        tag == readCurrentXmlTag();
    }
}
 
int main()
{
    Tree tree;
    tree.parseXML();
   
    tree.draw();
 
    return 1;
}
[+][-]11/01/09 11:31 PM, ID: 25717551

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 08:34 AM, ID: 25720850

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 08:38 AM, ID: 25720901

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 09:05 AM, ID: 25721198

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/02/09 09:16 AM, ID: 25721306

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 09:19 PM, ID: 25726236

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/02/09 11:35 PM, ID: 25726698

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/02/09 11:40 PM, ID: 25726719

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/02/09 11:59 PM, ID: 25726809

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C++ Programming Language
Sign Up Now!
Solution Provided By: itsmeandnobodyelse
Participating Experts: 2
Solution Grade: A
 
 
[+][-]11/03/09 12:38 AM, ID: 25726979

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/09 01:24 AM, ID: 25727211

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 01:45 AM, ID: 25727313

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/09 01:59 AM, ID: 25727383

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 09:40 AM, ID: 25731437

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/09 09:52 AM, ID: 25731555

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 09:56 AM, ID: 25731605

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/09 01:40 PM, ID: 25734089

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/09 11:18 PM, ID: 25737108

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 11:21 PM, ID: 25737124

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/09 11:29 PM, ID: 25737144

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/09 11:39 PM, ID: 25737182

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 12:32 AM, ID: 25737392

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 12:42 AM, ID: 25737427

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 12:43 AM, ID: 25737431

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 09:45 AM, ID: 25741862

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 03:43 PM, ID: 25745412

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 04:07 PM, ID: 25745556

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 10:35 PM, ID: 25747185

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 10:38 PM, ID: 25747203

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/09 10:55 PM, ID: 25747251

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/09 11:22 PM, ID: 25747357

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 12:21 AM, ID: 25747557

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 12:27 AM, ID: 25747575

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 12:38 AM, ID: 25747622

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 12:39 AM, ID: 25747624

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 12:42 AM, ID: 25747635

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 12:46 AM, ID: 25747646

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 12:49 AM, ID: 25747656

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 01:05 AM, ID: 25747726

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 01:18 AM, ID: 25747799

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 02:07 AM, ID: 25748001

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 08:55 AM, ID: 25751466

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 09:17 AM, ID: 25751677

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 09:34 AM, ID: 25751852

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 09:42 AM, ID: 25751920

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 09:49 AM, ID: 25751983

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 10:39 AM, ID: 25752473

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 11:21 AM, ID: 25752903

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 11:47 AM, ID: 25753157

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 12:12 PM, ID: 25753424

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 12:15 PM, ID: 25753453

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 12:39 PM, ID: 25753748

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/09 10:15 PM, ID: 25756957

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 11:25 PM, ID: 25757278

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/09 11:38 PM, ID: 25757329

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625