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 » Problem with XML
Problem with XML [message #39926] Sat, 11 May 2013 17:56 Go to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

Running this sample a "invalid Value type" exception is thrown:

xmldemo.cpp
#include <Core/Core.h>

using namespace Upp;

struct MyClass {
	Value val;
	void Xmlize(XmlIO& xml) {
		xml
			("Val", val);
	}
};

CONSOLE_APP_MAIN
{
	MyClass demo;
	
	String fileName = AppendFileName(GetDesktopFolder(), "demo.xml");
	
	try {
		LoadFromXMLFile(demo, fileName);
	} catch (XmlError error) {
		Cout() << "\nError: " << error;		
	}
	ReadStdIn();
}


demo.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE Demo>
<Demo>
</Demo>


A possible but ugly solution is to remove lines 405-406 in Value.cpp:

	if(Upp::IsNull(type))
		throw XmlError("invalid Value type");



In addition it would be great if LoadFromXML() would throw the exception to let the program to handle the errors, like this:
	catch(XmlError error) {
		throw error;
	}

Now the XmlErrors do not arrive to the program as LoadFromXML() catch them but do not re-throw them.


Best regards
Iñaki
Re: Problem with XML [message #39928 is a reply to message #39926] Sun, 12 May 2013 12:22 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Well, it is sort of question whether such XML should be considered OK or buggy for Xmlize, however, I have changed the code to assign void Value in case that value is missing.

As for LoadFromXML* catching exception, well, that is the defined contract, it simply returns false in case of any error.

Perhaps we could implement another set LoadFrom*X that does throw exception...

Mirek
Re: Problem with XML [message #39930 is a reply to message #39928] Sun, 12 May 2013 14:22 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

Thank you for the Value issue. Actually U++ XML functions let to change Xmlize() functions without throwing errors. That is excellent because it permits developers to install new versions that will handle gracefully old user xml files.

This was in my case the reason of finding the error.

About the exceptions: XML files can be changed by hand by users. It is good to know not only that the file format is wrong, but what is the failure and where is it to guide the user to solve it.



Best regards
Iñaki
Re: Problem with XML [message #39931 is a reply to message #39930] Sun, 12 May 2013 15:56 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

There is a DDUMP() in XML.h that is a compiling error in release mode.


Best regards
Iñaki
Re: Problem with XML [message #39936 is a reply to message #39930] Mon, 13 May 2013 08:57 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Sun, 12 May 2013 08:22


About the exceptions: XML files can be changed by hand by users. It is good to know not only that the file format is wrong, but what is the failure and where is it to guide the user to solve it.




Added to RM.
Re: Problem with XML [message #40004 is a reply to message #39936] Sat, 25 May 2013 13:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
mirek wrote on Mon, 13 May 2013 02:57

koldo wrote on Sun, 12 May 2013 08:22


About the exceptions: XML files can be changed by hand by users. It is good to know not only that the file format is wrong, but what is the failure and where is it to guide the user to solve it.




Added to RM.


Applied patch by Sender Ghost that provides TryLoadFromXML* functions.
Re: Problem with XML [message #40012 is a reply to message #40004] Sun, 26 May 2013 15:19 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello Mirek

It is right, although it is not strictly necessary to return a bool. With try-catch a void could be enough.


Best regards
Iñaki
Re: Problem with XML [message #40014 is a reply to message #40012] Sun, 26 May 2013 16:28 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Sun, 26 May 2013 09:19

Hello Mirek

It is right, although it is not strictly necessary to return a bool. With try-catch a void could be enough.


I was considering this too. Anyway, perhaps it is a good idea to distinguish empty input.
Previous Topic: glutBitmapCharacter undefined reference.
Next Topic: Bug in Core/Stream.cpp
Goto Forum:
  


Current Time: Thu Apr 25 20:51:38 CEST 2024

Total time taken to generate the page: 0.03621 seconds