# Small XML questions

## Recommended Posts

Ey-Lord    225
Hey guys ! First of all, im a real newvie in XML, i just read some tutorials today . I made a simple exemple.xml And it gives me an error ..i cant understand why :
<?xml version="1.0"?>
<!ENTITY lien "Ami de moi">

<classe>

<eleve age= "21" >
<name> Jeremy </name>
<relation>&lien;</relation>
</eleve>

<eleve age= "22" >
<name> Anne </name>
<relation>&lien;</relation>
</eleve>

</classe>

error -> a DTD declaration is forbidden outside a DTD ... My second question is more like a request ; if somone got a link to a very "user-friendly" tutorial on how to start parsing a simple xml file in c++ ( i need to know everything, from the download of the files (lib, headers ect..) to a simple exemple in c++. Thx by advance .

##### Share on other sites
Drew_Benton    1861
Quote:
 The ENTITY statement is used to define entities in the DTD, for use in both the XML document associated with the DTD and the DTD itself. An ENTITY provides an abbreviated entry to place in your XML document. The abbreviated name is what you provide for the name parameter. ENTITYs are extremely useful for repeating information or large blocks of text that could be stored in separate files. The abbreviated name is followed by a ; in the XML document (&abbName;)

Take a look at that MSDN reference, it will show you what you need to do. Right now the ENTITY tag needs to be in a .DTD file, not a .XML [smile]. I don't really know of any tutorials on how to write an XML parser, but it is failry straight forward when you want to do just support the basics of XML files. It is basically just file parsing. I wrote my own simple XML parser a while back and it worked fine - for the most - when I was using them as config files for data driven apps.

##### Share on other sites
jedifreeman    169
you want to parse XML in C++?

http://www.grinninglizard.com/tinyxml/index.html

##### Share on other sites
Toolmaker    967
TinyXML is small, lightweight and easy to integrate. However, the documentation is nothing more than the doxygen docs. You'll need to spent some time figuring out which classes you need to use where. In the end, it's pretty simple.

Toolmaker

##### Share on other sites
Genjix    100
Xml Library. Here i made you a n00bish xml library to use.
try{	Xml::Document doc = "path/to/doc.xml";}catch(const Xml::NoDocument &nd){	cerr << nd.What();	cerr << "error in " << nd.docsrc << "\n";}Xml::Element root = doc();     // anonymous rootXml::Element root = doc("root");Xml::Elemenet subelement = root("eleve");try{	int x = subelement.Int("age");	bool onoff = subelement.Bool("onoff");	string name = subelement.Str("name");	const char *a = subelement["a"];	if(!a)		cout << "attribute a does not exist!\n";}catch(const Xml::NoAttribute &na){	cerr << na.What();	cerr << na.element << " in " << na.attribute << "\n";}// loop through elements under subelement named "object"for(Xml::Element j = subelement("object") ; j ; j.Sibling("object")){	// do stuff}

just compile all the .cpp files in there (Whew! RSI :( )

##### Share on other sites
Ey-Lord    225
First, concerning my Entity error ... sry, but it wasnt menioned anywhere in the tutorial i read that this should be in another file :)
Anyway thx, i'll search more ont this.

And i just downloaded TinyXML parser, i'll try now to instal it, run it :)
i'll let you guys know if i suceed or not ;)

##### Share on other sites
Kylotan    10011
Quote:
 Original post by ToolmakerTinyXML is small, lightweight and easy to integrate. However, the documentation is nothing more than the doxygen docs.

That's a little unfair on TinyXML. If you read the first page of the docs - and a lot of people skip this essential step, sadly - there is a pretty clear example at the bottom which details pretty much all the classes and how they relate to a simple XML document.

##### Share on other sites
Ey-Lord    225
re guys,
In the docs, it says taht i need to include about 5 file (.h .cpp ) , i did taht and i got a bunch of error ; and i looked at their exemples, they only include tinyxml.h; so did i, and then, no more error ;)

after that i tried to load a .xml , with this :
 TiXmlDocument doc( "test.xml" );	   doc.LoadFile();

it gives me 7 unresolved external ... i must have missed something O_o
any ideas ?

[Edited by - Ey-Lord on March 28, 2005 3:33:04 AM]

##### Share on other sites
Kylotan    10011
It says, "TinyXml is designed to be easy and fast to learn. It is two headers and four cpp files. Simply add these to your project and off you go."

Out of interest, if you're not used to C++, why are you choosing this to handle XML with? A language like Java or Python would make life easier here if you just need to write something for a specific task.

##### Share on other sites
Drew_Benton    1861
How complex of XML files are you trying to load? TBH, I found TinyXML just a little to complex for me the first time I tried it. Granted I did not read everything, but I wanted something that was plug and play, so I decided to write my own. I'd be more than glad to show the code if you are just doing simple XML stuff, such as loading data as configuration settings. So when I say XML parser, it is very lightweight thus limited, but it did work for the most part [wink] I just have not gotten around to updating it and revising.

##### Share on other sites
Ey-Lord    225
him i dug a little deeper, and i found that tinyXML isnt the real problem ; my problem is somewhere in my class-model .

Because if i put all those include in my MAIN class, there is no pb to compile .
But in my little class , it gives me many error like this one

xxxx function is already defined in mainclass.cpp ...

I dont see where is my pb :/

edit @ Kylotan
Im not sure of what you mean by "include them to your vc++ project"
I just added them with the option " add existing item" and them i wrote some include in my file like this :

#ifndef CLASSE_CTEXTEDIALOGUE#define CLASSE_CTEXTEDIALOGUE// headers de la SDL#include <sdl\SDL_opengl.h> #include <sdl\SDL.h>// headers d'openGL #include <gl\gl.h>#include <gl\glu.h>#include <gl\glaux.h>#include <string>#include <iostream>#include <sstream>#include "../Manager/cItem.h"#include "../Object-Model/cTexteDialogueModel.h"#include "cFont.h"#include "../Manager/cTexteManager.h"#include "../Parser/tinyxml.cpp"#include "../Parser/tinyxml.h"#include "../Parser/tinyxmlerror.cpp"#include "../Parser/tinyxmlparser.cpp"#include "../Parser/tinystr.h"#include "../Parser/tinystr.cpp"/* --------------------------------------------------------------------------------- */// Classe représentant un dialogue dans le jeu ./* --------------------------------------------------------------------------------- */ class cTexteDialogue : public cItem{        public :          ~cTexteDialogue();		   cTexteDialogue();		   void Init() ;		   void Draw() ;		   void TraiterTexte(std::string temp);		   void TraiterBalise(std::string balise);		   int  getWidth(std::string temp);		   void BaliseColor(std::string balise, int mode);  public :	      int xpos;		  int ypos;		  cFont * font ;		  std::string TexteInitial ;		  int done ;};#endif

do i need to do some more things?

##### Share on other sites
Drew_Benton    1861
Can you post the errors please. That should point to where the problem lies.

##### Share on other sites
Ey-Lord    225
EyLord error LNK2005: "public: char const * __thiscall TiXmlElement::Attribute(char const *,double *)const " (?Attribute@TiXmlElement@@QBEPBDPBDPAN@Z) already defined in EyLord.obj

60* this error :)

##### Share on other sites
Drew_Benton    1861
Yes:
#include "../Parser/tinyxml.cpp"#include "../Parser/tinyxml.h"#include "../Parser/tinyxmlerror.cpp"#include "../Parser/tinyxmlparser.cpp"#include "../Parser/tinystr.h"#include "../Parser/tinystr.cpp"

You do not include .cpp files buddy [smile] Just add them to the project workspace. That should fix a lot of them.

Ey-Lord    225
pb solved :)
ty :D