Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Using DOM like XML parser
Re: Using DOM like XML parser [message #6475 is a reply to message #6474] Mon, 13 November 2006 23:35 Go to previous messageGo to previous message
zsolt is currently offline  zsolt
Messages: 698
Registered: December 2005
Location: Budapest, Hungary
Contributor
For fast reference, this is the new Open method, loading, parsing the XML file and putting its content to the ArrayCtrl:
void AddressBook::Open()
{
	if(!fs.ExecuteOpen()) return;
	filename = fs;
	array.Clear();
	try {
		String d = LoadFile(filename);
		XmlNode n = ParseXML(d);
		if(n.GetCount()==0 || n[0].GetTag() != "AddressBook")
			throw XmlError("No AddressBook tag in ");
		const XmlNode &ab = n[0];
		array.SetCount(ab.GetCount());
		for(int i=0; i < ab.GetCount(); i++){
			const XmlNode &person = ab[i];
			for(int j=0; j < person.GetCount(); j++){
				const XmlNode &prop = person[j];
				if(prop.IsTag(TAG_NAME)) array.Set(i, TAG_NAME, prop[0].GetText());
				else if(prop.IsTag(TAG_SURNAME)) array.Set(i, TAG_SURNAME, prop[0].GetText());
				else if(prop.IsTag(TAG_ADDRESS)) array.Set(i, TAG_ADDRESS, prop[0].GetText());
				else if(prop.IsTag(TAG_EMAIL)) array.Set(i, TAG_EMAIL, prop[0].GetText());
			}
		}
	}
	catch(XmlError &e) {
		Exclamation("Error reading the input file:&" + DeQtf(e) );
	}
}
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Groovey
Next Topic: An OpenGL ctrl for Linux / X11
Goto Forum:
  


Current Time: Thu May 16 10:11:21 CEST 2024

Total time taken to generate the page: 0.01976 seconds