But I havent found the correct way to parse it. I dont know if the file is wrong and I should redefine the structure or if Im using the wrong parsin method. Can somebody clear me how to do it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have this file:
<?xml version="1.0" ?>
<map>
<info
version=1
id=1
name="Testing map"
msg="Welcome to Testing map"
pvp="no"
/>
<-- NPCs spawn points -->
<npcs>
<npc id=1000 type=2 name="Fat Ninja" x=4900 y=2000 />
<npc id=1001 type=3 name="Small Ninja" x=4920 y=2010 />
</npcs>
</map>
But I havent found the correct way to parse it. I dont know if the file is wrong and I should redefine the structure or if Im using the wrong parsin method. Can somebody clear me how to do it?
Can't say if you're parsing it right or not because you didn't post any code.
However, your xml is invalid -- attributes must be quoted, they can be unquoted, like old HTML.
Tip: put your xml in a file and load it in IE or firefox -- if it loads ok you'll get a nice tree structure, proving that your xml is ok.
HTH
Ellers
I fixed the xml and here is the parsing code:
TiXmlHandle chandle(&mapfile);
//load map info
cout <<"Looking for info...";
cvalue=chandle.FirstChild("map").FirstChild("info").Element();
//cvalue=chandle.FirstChild("info").Element(); //another variant
if (cvalue) {
name = cvalue->Attribute("name");
welcomsg = cvalue->Attribute("welcome");
cvalue->QueryIntAttribute("id", &id);
cout <<id<<name<<endl;
} else cout<<"Not found info"<<endl;
This fails to find the desired section. Also, the following approach fails with a crash:
TiXmlElement *root = mapfile.RootElement();
//load map info
cout <<"Looking for info...";
cvalue=root->FirstChildElement("info");
if (cvalue) {
name = cvalue->Attribute("name");
welcomsg = cvalue->Attribute("welcome");
cvalue->QueryIntAttribute("id", &id);
cout <<id<<name<<endl;
} else cout<<"Not found info"<<endl;
Which line causes the crash, according to your debugger?
Are you on win32, linux, or other?
What is the latest XML?
A good way to check if you XML is valid is to load it into a browser. Both IE and Firefox have very good parsers and can detect invalid XML.
lee