1 Attachment(s)
Need some help with TinyXML
Hello, I need some help figuring out how to read the next element on the list. I first need to get out of the <Account> loop though, but i tired using break, but it doesn't work.
I kept getting an error when my parser get to <VirtualUser>.
Currently my code looks like this:
Code:
#include <iostream>
#include <string>
#include "tinyxml.h"
using std::cout;
using std::string;
using namespace std;
int main() {
string file = "test7.xml";
TiXmlDocument doc(file.c_str());
if (doc.LoadFile()) {
TiXmlElement *root = doc.RootElement();//goes to completeAccount
for(TiXmlElement* example2 = root->FirstChildElement(); example2;
example2 = example2->NextSiblingElement()) { //goes to account
TiXmlElement* level2 = example2->FirstChildElement(); //goes to the level where name is
cout << "\n Name: ";
cout << example2->FirstChild("name")->FirstChild()->Value();//take child name and turn in to string so i can use cout on it
cout << "\n type:";
cout << example2->FirstChild("type")->FirstChild()->Value();
cout << '\n';
break;//I used break to get out of the look because when it tired to keep going to read virtualUser It gave me an error.
}
cout << "Break ";
for(TiXmlElement* example2 = root->FirstChildElement(); example2;
example2 = example2->NextSiblingElement()) {
cout << "\n Login Name: ";
cout << example2->FirstChild("loginName")->FirstChild()->Value();
}
}
}
My xml looks like this:
Attachment 11032
Optional: My other question is for example I noticed i get an error if one of my account doesn't have "type" in it how would i get it to just put "null" instead of giving me an error?