Web Connection
How to convert image file to XML using wwXML?
Gravatar is a globally recognized avatar based on your email address. How to convert image file to XML using wwXML?
  Yonggu
  All
  Feb 26, 2019 @ 12:10pm

Hello Rick

I have been developing n-tier application with Web Connection 7.02 and it has thick client. I need to convert image file to XML and I want to make it using wwXML.

For a few days, I tried it but I haven't made it.

help me out, Please.

Yonggu

Gravatar is a globally recognized avatar based on your email address. re: How to convert image file to XML using wwXML?
  Rick Strahl
  Yonnggu
  Feb 26, 2019 @ 01:49pm

Should be easy enough. Make sure you cast your binary data to BLOB.

DO wwXML
loXml = CREATEOBJECT("wwXML")
loObj = CREATEOBJECT("EMPTY")
ADDPROPERTY(loObj,"FirstName","Rick")
ADDPROPERTY(loObj,"RawData")

*** Assign some binary data
loObj.RawData = CAST( "434234234234" + CHR(0) + "More data" as Blob)

? loObj.FirstName
? loObj.RawData

lcXml = loXml.ObjectToXml(loObj, "persondata")
? lcXML
_cliptext = lcXML

This produces:

<?xml version="1.0"?>
<xdoc>
	<persondata type="object" class="empty">
		<firstname>Rick</firstname>
		<rawdata>343334323334323334323334004D6F72652064617461</rawdata>
	</persondata>
</xdoc>

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to convert image file to XML using wwXML?
  Yonggu
  Rick Strahl
  Feb 26, 2019 @ 06:00pm

Thanks Rick.

I can now convert image file to XML using wwXML.

But, I have a another problem now.
The problem is how to convert xml to image file.

This is my sample code and it doesn't work.


CLEAR

DO wwXML loXml = CREATEOBJECT("wwXML")

loObj = CREATEOBJECT("EMPTY")
ADDPROPERTY(loObj,"FirstName","Rick")
ADDPROPERTY(loObj,"RawData")

*** Assign some binary data
loObj.RawData = CAST( FILETOSTR("c:\temp\test.jpg") as Blob)

? loObj.FirstName
? loObj.RawData

lcXml = loXml.ObjectToXml(loObj)

LOCAL loResult
loResult = CREATEOBJECT("EMPTY")
ADDPROPERTY(loResult,"FirstName","Rick")
ADDPROPERTY(loResult,"RawData")

loResult = loXML.XMLToObject(lcXml, loResult)

?loResult.FirstName
?loResult.RawData

Gravatar is a globally recognized avatar based on your email address. re: How to convert image file to XML using wwXML?
  Rick Strahl
  Yonnggu
  Feb 26, 2019 @ 06:19pm

Actually after doing some more checking - it's not supported in either direction. The output generated is binhex encoded which is just the default for TRANSFORM() on a blob value.

I've added functionality to properly handle binary (Blob or type Q) content which should be base64 encoded. It'll be in the next update.

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to convert image file to XML using wwXML?
  Yonggu
  Rick Strahl
  Feb 27, 2019 @ 02:00am

Hi Rick.

I am developing new application so that I really need the functionality that you have added. If I have to wait for the next update, maybe it will be a hard time to me.

I don't know what to do, is there any way I can get it before the next update?

Think positively, please.

Yonggu

Gravatar is a globally recognized avatar based on your email address. re: How to convert image file to XML using wwXML?
  Rick Strahl
  Yonnggu
  Feb 27, 2019 @ 12:00pm

You can easily do what you need to for now.

You can serialize using the current code. Then deserialize the binary data into a string and manually convert with for


loObj.RawData = ""  && Assume string
loObj.FirstName = ""

loXml.XmlToObject(lcXml,loObj)

? loObj.FirstName
? loObj.RawData  && bin Hex string

*** Convert back to binary
loObj.RawData = CAST( STRCONV(loObj.RawData,16) as Blob)
? loObj.RawData

The updated wwXML code will serialize to base64 and automatically deserialize. That code is then simpler:

loObj.RawData = CAST(CHR(0) as BLOB)  && set a binary value
loObj.FirstName = ""

loXml.XmlToObject(lcXml,loObj)

? loObj.FirstName
? loObj.RawData  && binary data

+++ Rick ---

Gravatar is a globally recognized avatar based on your email address. re: How to convert image file to XML using wwXML?
  Rick Strahl
  Yonnggu
  Feb 27, 2019 @ 04:56pm

Please use the code markup features in your messages when you post here. Click the </> button to paste your hightlight your code.

Gravatar is a globally recognized avatar based on your email address. re: How to convert image file to XML using wwXML?
  Yonggu
  Rick Strahl
  Feb 27, 2019 @ 05:16pm

I am sorry that I didn't know the code markup features.
I am going to post again.

The code that you showed me is very helpful.

Everything is going well when wwXML.nCreateDataStructure is 0. But, when wwXML.nCreateDataStructure is 1, there is something wrong.

What do you think is the problem?

DO wwXML

loXml = CREATEOBJECT("wwXML")  
loXML.nCreateDataStructure = 1
	
*--->
loObj = CREATEOBJECT("EMPTY")  
ADDPROPERTY(loObj,"FirstName","Rick")  
ADDPROPERTY(loObj,"RawData")

*** Assign some binary data
loObj.RawData = CAST( FILETOSTR("c:\temp\test.jpg") as Blob)

*? loObj.FirstName  
*? loObj.RawData

lcXml = loXml.ObjectToXml(loObj)


LOCAL loResult  
loResult = .NULL.

loResult = loXML.XMLToObject(lcXml, loResult)

loResult.RawData = CAST( STRCONV(loResult.RawData, 16) as Blob)

?STRTOFILE(loResult.RawData, "c:\temp\test_result.jpg")

Gravatar is a globally recognized avatar based on your email address. re: How to convert image file to XML using wwXML?
  Rick Strahl
  Yonnggu
  Feb 27, 2019 @ 06:52pm

The problem is that the binary code is not supported there.

I think the easiest solution for now is to manually encode to base64 and store the data as text when serializing, then retrieve the text on the way out and convert back from base64.

I'm going to push out an update shortly but there are a few other things int he serializer that don't work right that I'm fixing while I'm at it. I haven't looked at this XML code in a long time...

If you're using two way serialization (ie. you own both sides of the connection) then maybe using JSON is a better choice? That just works now.

+++ Rick ---

© 1996-2024