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    | 
		 
		
			
				
				
				
					
						  
						zsolt
						 Messages: 702 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) );
	}
} 
		
		
		
 |  
	| 
		
	 | 
 
 
 |  
  
 
Goto Forum:
 
 Current Time: Tue Nov 04 13:56:56 CET 2025 
 Total time taken to generate the page: 0.09242 seconds 
 |