Hi guys
I have bit of a puzzle. :-)
In an old part of our system we are saving XML-files to a temp-table as raw data. We can get it out, by copying the rawdata into a memptr.
This memptr contains an XML. How can I easily convert this memptr containing XML into JSON in an elegant fashion?
Hopefully you guys can help me out a bit.
Deleted...didn't read the problem correctly.
You will probably have to read the xml into a temp-table via dataset, then writing it to json.
Update from Progress Community
onnodehaan Hi guys
I have bit of a puzzle. :-)
In an old part of our system we are saving XML-files to a temp-table as raw data. We can get it out, by copying the rawdata into a memptr.
This memptr contains an XML. How can I easily convert this memptr containing XML into JSON in an elegant fashion?
Hopefully you guys can help me out a bit.You received this notification because you subscribed to the forum. To stop receiving updates from only this thread, go here.
Flag this post as spam/abuse.
If the XML structure allows reading into a dataset/temp-table via READ-XML, you could then use WRITE-JSON to write it out again.
Otherwise, use the SAX-READER to parse the XML, and from it's callbacks use the Progress.Json.* classes to build the JSON string.
As first, generic approach you'll probably want map each XML element to a new JSON object, and add XML attributes as attributes of that JSON object. Map XML sub-elements to a JSON array of JSON objects.
If you know what JSON layout you want to use for a given XML document type, change that approach as desired.
(You could also use the X-DOCUMENT DOM tree, but well, for this purpose the SAX approach tends to be more elegant and lightweight.)
Hi guys
Yes both options came to mind with me as well. Only "problem" that I have is that it requires a lot of code to use sax-reader for example. And construct the JSON manually.
But unless someone comes up with a fast, shorter, way: I guess using sax-reader is indeed the least worst option :-)
In some cases I might not. I don't know the type of XML beforehand.
One aproach I would suggest (if you are comfortable using .NET controls) is running XSL transformation that converts XML to JSON. Maybe this link might help: stackoverflow.com/.../xsl-to-convert-xml-to-json