Closed GoogleCodeExporter closed 9 years ago
Hi, finally I got it. The problem was that I mixed up the char array with
std::string.
Here a snipped how to parse through a xml file: Maybe you could make a tutorial
out
of it ;)
XML-file to be parsed:
<?xml version="1.0" encoding="UTF-8" ?>
<Fruits>
<Apple colour="green" price="1.1" amount="10" />
<Banana colour="yellow" price="1.5" amount="10" />
<Cherry colour="red" price="2.5" amount="1" />
</Fruits>
Approach how to achieve that:
[code]
#include <iostream>
#include <ticpp.h>
// simple function to parse a xml file
void Parse(const char* pcFilename);
int main()
{
// whatch out for exceptions
try
{
// parse the xml file with the name fruits.xml
Parse("fruits.xml");
}
catch(ticpp::Exception& ex)
{
std::cout << ex.what();
}
return -1;
}
void Parse(const char* pcFilename)
{
// first load the xml file
ticpp::Document doc(pcFilename);
doc.LoadFile();
// parse through all fruit elements
ticpp::Iterator<ticpp::Element> child;
for(child = child.begin(doc.FirstChildElement()); child != child.end(); child++)
{
// The value of this child identifies the name of this element
std::string strName;
std::string strValue;
child->GetValue(&strName);
std::cout << "fruit: " << strName << std::endl;
std::cout << "-------------" << std::endl;
// now parse through all the attributes of this fruit
ticpp::Iterator< ticpp::Attribute > attribute;
for(attribute = attribute.begin(child.Get()); attribute != attribute.end();
attribute++)
{
attribute->GetName(&strName);
attribute->GetValue(&strValue);
std::cout << strName << ": " << strValue << std::endl;
}
std::cout << std::endl;
}
}
[/code]
Original comment by a.schre...@gmx.net
on 3 May 2009 at 9:18
I added a tutorial section to the Wiki. Thanks.
Original comment by rpusz...@gmail.com
on 3 May 2009 at 6:00
Original issue reported on code.google.com by
a.schre...@gmx.net
on 1 May 2009 at 8:16