|
|
Home » U++ Library support » U++ Core » DeXml() incomplete
DeXml() incomplete [message #26960] |
Mon, 14 June 2010 00:35 |
Didier
Messages: 680 Registered: November 2008 Location: France
|
Contributor |
|
|
Hi,
I've been trying to put PNG images in an XML file, but it always failed.
After some investigation it seems that DeXml function is incomplete:
It takes a 'char*' as input data and then searches for the '0' value to find end of string !
With PNG images this does not work !
If you change 'char*' to String and use Begin() & End() methods instead of searching for '0' value, then it works.
Here is a sample code that illustrates what I say:
#include <Core/Core.h>
#include <Draw/Draw.h>
#include <plugin/png/png.h>
using namespace Upp;
#define IMAGECLASS CtrlImg
#define IMAGEFILE <CtrlLib/Ctrl.iml>
#include <Draw/iml_header.h>
#define IMAGECLASS CtrlImg
#define IMAGEFILE <CtrlLib/Ctrl.iml>
#include <Draw/iml_source.h>
String MyDeXml(const String& str, byte charset, bool escapelf)
{
if(charset == CHARSET_DEFAULT)
charset = GetDefaultCharset();
StringBuffer result;
const char* s= str.Begin();
const char* end= str.End();
for(; s != end; s++)
/**/ if(*s == '<') result.Cat("<");
else if(*s == '>') result.Cat(">");
else if(*s == '&') result.Cat("&");
else if(*s == '\'') result.Cat("'");
else if(*s == '\"') result.Cat(""");
else if((byte)*s < ' ' && (escapelf || *s != '\n' || *s != '\t'))
result.Cat(NFormat("&#x%02x;", (byte)*s));
else if(!(*s & 0x80) || charset == CHARSET_UTF8) result.Cat(*s);
else result.Cat(ToUtf8(ToUnicode(*s, charset)));
return result;
}
CONSOLE_APP_MAIN
{
PNGEncoder pngEncoder;
String str = pngEncoder.SaveString( CtrlImg::error() );
XmlNode xmlDoc;
XmlNode& myDoc = xmlDoc.Add("MY_DOC_TAG");
XmlNode& myTextTag = myDoc.Add("MyTextTag");
myTextTag.AddText( str );
LOG("----------- STR() =");
LOG(String("length=") << str.GetLength());
LOG(str);
LOG("-----------");
LOG("-----------AsXml() =");
LOG(String("length=") << AsXML(xmlDoc).GetLength());
LOG(AsXML(xmlDoc));
LOG("-----------");
LOG("-----------DeXml() =");
LOG(String("length=") << DeXml(str).GetLength());
LOG(DeXml(str));
LOG("-----------");
LOG("-----------DeXml(CHARSET_DEFAULT, true) =");
LOG(String("length=") << DeXml(str, CHARSET_DEFAULT, true).GetLength());
LOG(DeXml(str, CHARSET_DEFAULT, true));
LOG("-----------");
LOG("-----------MyDeXml() =");
LOG(String("length=") << MyDeXml(str, CHARSET_DEFAULT, true).GetLength());
LOG(MyDeXml(str, CHARSET_DEFAULT, true));
}
the resulting log file is the following:
----------- STR() =
length=419
PNG
IHDR0-JjIDAThn1g7OP6O&!dgˎl6;90ߊE c i?tv+B9偌9{np"+wmgL|-ArNpAxl W|#"މeKl݅yEv `~H&B=gжшxs`$PDz,z6*@k "PlBgmsHt(kI'9vBȴ@[%9
fH#&">ȼ7N/k\z-銤,|42hxf5I6~nJ<+!=WC⁅ћfazRIENDB`
-----------
-----------AsXml() =
length=186
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE MY_DOC_TAG>
<MY_DOC_TAG>
<MyTextTag xml:spaces="preserve">PNG

</MyTextTag>
</MY_DOC_TAG>
-----------
-----------DeXml() =
length=28
PNG


-----------
-----------DeXml(CHARSET_DEFAULT, true) =
length=28
PNG


-----------
-----------MyDeXml() =
length=837
PNG

���
IHDR���0���-���J��jIDAThn1g7OP6O&!dgˎl6;90ߊE c i?tv+B9偌9{np"+wmgL|-ArNpAxl	W|#"މeKl݅yEv `~H�&B=gжшxs`$P
,z6*@k "PlBgmsHt(kI'9vBȴ@[%9
 fH�#&">ȼ7N/k\z-銤,|42hxf5I6~nJ<+!=WC⁅ћfazR����IENDB`
Note: there is a 100% growth factor on the data size when converted to xml: this could be optimized using base 64 encoding for example (30% growth factor)
I suggest adding overloads with 'String' parameter for some functions/methods in order to avoid this drawback.
|
|
|
|
Re: DeXml() incomplete [message #26967 is a reply to message #26963] |
Tue, 15 June 2010 20:11 |
Didier
Messages: 680 Registered: November 2008 Location: France
|
Contributor |
|
|
Hi Mirek,
Thanks for the correction, it works fine: I can write my xml file with images just fine.
But when I wan't to open the file .... I get a "Unexpected end of file" exception.
I'll look into it tonight
When finished, I'm gonna post an example app with the following things:
- Image editing using the fresh EditImage ctrl
- storing the image in database
- exporting the image in xml
[Updated on: Tue, 15 June 2010 20:15] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Mon Apr 29 13:24:44 CEST 2024
Total time taken to generate the page: 0.02442 seconds
|
|
|