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 » Community » Newbie corner » XML exercise
Re: XML exercise [message #36080 is a reply to message #35990] Tue, 24 April 2012 21:06 Go to previous messageGo to previous message
idkfa46 is currently offline  idkfa46
Messages: 155
Registered: December 2011
Experienced Member
I try to enliven this topic...
here my code to answer the first question about reading XLM structure and show stored values.

bool prova4::Load(const char *xml)
{
	try {
		XmlParser p(xml);
		while(!p.IsTag())
			p.Skip();
		int i =0;
		p.PassTag("prova");
		while(!p.End())
			if(p.Tag("car"))	
			{
				String car = p.ReadText();
				dl.Add(i, car);
				if(car == carDefault)
				{
					dl.SetIndex(i);
					loadSelect(xml, car);
				}
				i++;
				p.End();
			}
			else
			{
				p.Skip();
			}
		return true;
		}
	catch(XmlError e) 
	{
		Exclamation("XML error: " + e);
		return false;	
	}
}

bool prova4::loadSelect(const char *xml, String car)
{
	try {
		XmlParser p(xml);
		while(!p.IsTag())
			p.Skip();
		p.PassTag("prova");
		while(!p.End())
			if(p.Tag("car"))
				if(p.ReadText() == dl.GetValue())
				{
					p.End();
					p.PassTag("value");	
					while(!p.End())
							if(p.TagE("Select1"))
								select1 = ScanDouble(p["value"]);
							else 
							if(p.TagE("Select2"))
								select2 = ScanDouble(p["value"]);
							else
							if(p.TagE("Select3"))
								select3 = ScanDouble(p["value"]);			
				}
				else
				{
					p.End();
					p.PassTag("value");
					p.SkipEnd();
				}
		return true;
	}
	catch(XmlError e) 
	{
		Exclamation("XML error: " + e);
		return false;	
	}
}


dialog.xml
<?xml version="1.0"?>

<prova>
<car>A</car>
<value>
	<Select1 value="1"/> 
	<Select2 value="2"/> 
	<Select3 value="3"/>
</value>
<car>B</car>
<value>
	<Select1 value="4"/> 
	<Select2 value="5"/> 
	<Select3 value="6"/>
</value>
<car>C</car>
<value>
	<Select1 value="7"/> 
	<Select2 value="8"/> 
	<Select3 value="9"/>
</value>
<car>D</car>
<value>
	<Select1 value="10"/> 
	<Select2 value="11"/> 
	<Select3 value="12"/>
</value>
</prova>


Is this the right way ? any advice on it?

Regards,
Matteo
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: fills the DropList from VectorMap
Next Topic: Search for constant and show it....
Goto Forum:
  


Current Time: Sun May 12 11:49:07 CEST 2024

Total time taken to generate the page: 0.03071 seconds