Small XML questions

Started by
13 comments, last by Ey-Lord 19 years ago
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 .
Advertisement
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.
you want to parse XML in C++?

http://www.grinninglizard.com/tinyxml/index.html
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

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 :( )
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 ;)
Quote:Original post by Toolmaker
TinyXML 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.
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]
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."

Adding them to your project is including them in the compilation process: ie. add to your project in Visual C++, or your makefile in GCC.

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.
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.

This topic is closed to new replies.

Advertisement