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 » U++ Library support » U++ Core » XML parsing error
XML parsing error [message #16836] Wed, 16 July 2008 13:23 Go to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

hello

i am sorry if my Question was boring for you to solve but i dont know what is the proplem

i made this structer and class

struct message
{
	String title;
	String body;
	String popup;
	String link;
	String attachment;
};
class news
{
	private:
	message Current_Message;
	String sender;
	public:
	news(XmlParser Xml_File)
	{
		while(!Xml_File.IsTag())
			Xml_File.Skip();
		Xml_File.PassTag("root");
		while(!Xml_File.IsEof())
		{
			if(Xml_File.Tag("new"))
			{
				if(Xml_File.Tag("message"))
				{
					while(!Xml_File.End())
					{
						if(Xml_File.Tag("title"))
							Current_Message.title = Xml_File.ReadText();
						if(Xml_File.Tag("body"))
							Current_Message.body = Xml_File.ReadText();
						if(Xml_File.Tag("popup"))
							Current_Message.popup = Xml_File.ReadText();
						if(Xml_File.Tag("link"))
							Current_Message.link = Xml_File.ReadText();
						if(Xml_File.Tag("attachment"))
							Current_Message.attachment = Xml_File.ReadText();
						else
						{
							Xml_File.Skip();
							continue;
						}
						Xml_File.PassEnd();
					}
				}
				else if(Xml_File.Tag("sender"))
				{
					sender = Xml_File.ReadText();
				}
				else
					Xml_File.Skip();
			}
		}
	}
	message GetMessage()
	{
		return Current_Message;
	}
	String GetSender()
	{
		return sender;
	}
	
	
};


this class takes xmlparser as constructor

and put the data in the private variables

when i call it from here

CISNotifier::CISNotifier() //project constructer
{
	CtrlLayout(*this, "Window title");
	
	HttpClient client;
	client.URL("http://cisclub.com/tecno/bta3/XML.xml");
	String content;
	content = client.ExecuteRedirect();
	XmlParser p(content);
	news obj(p);
	message m = obj.GetMessage();
	String s = obj.GetSender();
	static_text.SetText(s);
}


the program links but it dont work :S :S

please help me

you can check the xml file as the link is in the code
Re: XML parsing error [message #16846 is a reply to message #16836] Wed, 16 July 2008 23:32 Go to previous messageGo to next message
bytefield is currently offline  bytefield
Messages: 210
Registered: December 2007
Experienced Member
Well, you have some problems there Rolling Eyes ;
First, is better to don't do all that stuff in constructor because if XmlParser fail it raise an exception and gui things get undone and appear other problems, because the exception is raised in constructor.
Your program get linked and executed(you didn't know it run) but because you don't catch the exception it finish immediately after start or it enter in a infinite loop while checking your xml file(that depends on circumstances, in the state that you put it here it get in infinite loop and if you try to correct it, then you will get some exceptions).
My advice is to use a construction like that in main function.
try
{
	XMLTestF().Run();
}
catch(XmlError xmlerror)
{
	PromptOK(GetLastErrorMessage());
}
catch(...)
{
	PromptOK("Unknow exception");
}

Other problem I've spotted is that you're not checking all xml tags and you're expecting that "message" tag to appear after "new" tag, instead based on your file the tag "timing" follow "new" tag, so your parsing loop get infinite because of that.
Verdict: Defective by design. Razz

Andrei


cdabbd745f1234c2751ee1f932d1dd75
Re: XML parsing error [message #16847 is a reply to message #16846] Wed, 16 July 2008 23:47 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

		while(!Xml_File.IsEof())
		{
			if(Xml_File.Tag("new"))
			{
				if(Xml_File.Tag("message"))
				{
					while(!Xml_File.End())
					{
						if(Xml_File.Tag("title"))
							Current_Message.title = Xml_File.ReadText();
						if(Xml_File.Tag("body"))
							Current_Message.body = Xml_File.ReadText();
						if(Xml_File.Tag("popup"))
							Current_Message.popup = Xml_File.ReadText();
						if(Xml_File.Tag("link"))
							Current_Message.link = Xml_File.ReadText();
						if(Xml_File.Tag("attachment"))
							Current_Message.attachment = Xml_File.ReadText();
						else
						{
							Xml_File.Skip();
							continue;
						}
						Xml_File.PassEnd();
					}
				}
				else if(Xml_File.Tag("sender"))
				{
					sender = Xml_File.ReadText();
				}[B][SIZE=4]
				else
					Xml_File.Skip();[/SIZE][/B]
			}
		}


thanks

but isn't this else case must prevent infinite loop ??

the main proplem is that i dont totaly understand how these xml parsing functions work
Re: XML parsing error [message #16849 is a reply to message #16847] Thu, 17 July 2008 00:09 Go to previous messageGo to next message
bytefield is currently offline  bytefield
Messages: 210
Registered: December 2007
Experienced Member
You forgot to check for some tags...
<timing>
  <date>
    <day>15</day>
    <month>7</month>
  </date>
  <time>
    <hours>19</hours>
    <minutes>35</minutes>
  </time>
</timing>

... and because of that you get in loop, check for EOF, than you check for "new" tag, after that you check for "message" tag but because the next tag is "timing" the else part get executed and there you check for "sender" and because the current tag isn't "sender" tag you skip to next tag. Now the current tag is "date" and you get to the begin of the loop. You check for "new" tag and because current tag is "date" that if never get executed and you cpu run that loop again and again.

Just go trough your program step by step and see what I've explained above.

Edit:
Quote:

but isn't this else case must prevent infinite loop ??

you should have an else case also for "new" tag.


cdabbd745f1234c2751ee1f932d1dd75

[Updated on: Thu, 17 July 2008 00:12]

Report message to a moderator

Re: XML parsing error [message #16850 is a reply to message #16849] Thu, 17 July 2008 00:30 Go to previous messageGo to next message
TeCNoYoTTa is currently offline  TeCNoYoTTa
Messages: 138
Registered: July 2008
Location: Egypt
Experienced Member

thanks very much ......i appreciate your help

but please tell me what these functions do

  • Xml_File.End()
  • Xml_File.PassEnd()
  • Xml_File.Skip()

[Updated on: Thu, 17 July 2008 00:37]

Report message to a moderator

Re: XML parsing error [message #16856 is a reply to message #16850] Thu, 17 July 2008 15:50 Go to previous messageGo to next message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
TeCNoYoTTa wrote on Wed, 16 July 2008 18:30

thanks very much ......i appreciate your help
but please tell me what these functions do
  • Xml_File.End()
  • Xml_File.PassEnd()
  • Xml_File.Skip()



I agree with you on some confusion with the xml parsing functions.
Unfortunately, my gripe with the xml parser is that it requires a lot of code to make it work correctly.

  • The End() function checks to see if the current token is an ending tag (Ie. </day>). At the same time, it will advance to the next token.
  • The PassEnd() function calls End(). So it expects that you already known that the current token is an ending tag and you want to pass it and go to the next token. If it is not an ending tag, then it throws an exception.
  • The Skip() function skips tokens till the next tag is reached, skipping over the ending tags as you go.

Note, tags specified like: <singletag attr1="value"/> will register as true for being an ending tag!
I was able to account for this through loops like:
XmlParser xp(xmlstr);
...
while(!xp.End()){
    if(xp.Tag("mytag")){
        //read attributes from tag
        if(xp.IsEnd()){xp.PassEnd();} //this checks for singletag case
    }else{ xp.Skip(); }
}


I wish there was a way to just convert an entire xml string into a hierarchy of vector/vector-maps! Maybe I'll work on one.
Re: XML parsing error [message #16864 is a reply to message #16856] Thu, 17 July 2008 19:19 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
captainc wrote on Thu, 17 July 2008 09:50


I wish there was a way to just convert an entire xml string into a hierarchy of vector/vector-maps! Maybe I'll work on one.


Is not XmlNode just that?

Mirek
Re: XML parsing error [message #16865 is a reply to message #16864] Thu, 17 July 2008 20:55 Go to previous message
captainc is currently offline  captainc
Messages: 278
Registered: December 2006
Location: New Jersey, USA
Experienced Member
I didn't have much luck on XmlNode, but once I got the parsing working I didn't give it another thought. I'll give it a go. Thanks.
Previous Topic: NULL
Next Topic: XMLNode error
Goto Forum:
  


Current Time: Thu Mar 28 10:55:58 CET 2024

Total time taken to generate the page: 0.01059 seconds