[stackoverflow] [progress Openedge Abl] Progress 4gl: Exporting Xml Into Json Using Temp-tables

Status
Not open for further replies.
D

danioqq

Guest
im trying to convert XML file into JSON using temp-tables. I can take every data out of my XML and save it, but i also take additional relation field which is not necessary for me. I might be blind but i dont see the solution for that.

OUTPUT (json):

{"employees": {
"employee": [
{
"relation_id": null,
"id": 1,
"firstname": "aaa",
"lastname": "bbb",
"role": 1,
"photo": "smile.jpg"
},
{
"relation_id": null,
"id": 2,
"firstname": "ccc",
"lastname": "ddd",
"role": 1,
"photo": "smile.jpg"
},
{
"relation_id": null,
"id": 3,
"firstname": "www",
"lastname": "bbb",
"role": 0,
"photo": "smile.jpg"
},
{
"relation_id": null,
"id": 4,
"firstname": "kkk",
"lastname": "sdfsdf",
"role": 2,
"photo": "smile.jpg"
},
{
"relation_id": null,
"id": 5,
"firstname": "sdfsdf",
"lastname": "gsdg",
"role": 2,
"photo": "smile.jpg"
} ], "roles": [
{
"relation_id": null,
"role": [
{
"relation_id": null,
"id": 1,
"name": "Actor"
},
{
"relation_id": null,
"id": 2,
"name": "Student"
}
]
} ] }}


So i want to delete all the "relation_id" field so my output is without them, but i need them to make relations between temp-tables to take all the data. Any ideas?

Here is my code.

DEFINE VARIABLE start AS LOGICAL NO-UNDO.
DEFINE VARIABLE zapisz AS LOGICAL NO-UNDO.
DEFINE VARIABLE typ AS CHARACTER NO-UNDO.
DEFINE VARIABLE doPliku AS CHARACTER NO-UNDO.
DEFINE VARIABLE wartosc AS LOGICAL NO-UNDO.

DEFINE TEMP-TABLE employee NO-UNDO XML-NODE-NAME "employee"
FIELD relation_id AS RECID XML-NODE-TYPE "Hidden"
FIELD id AS INTEGER
FIELD firstname AS CHARACTER
FIELD lastname AS CHARACTER
FIELD role AS INTEGER
FIELD photo AS CHARACTER.

DEFINE TEMP-TABLE roles NO-UNDO XML-NODE-NAME "roles"
FIELD relation_id AS RECID XML-NODE-TYPE "Hidden".

DEFINE TEMP-TABLE role NO-UNDO XML-NODE-NAME "role"
FIELD relation_id AS RECID XML-NODE-TYPE "Hidden"
FIELD id AS INTEGER
FIELD name AS CHARACTER.

DEFINE DATASET employees
FOR employees, employee, roles, role
DATA-RELATION dr3 FOR roles, role RELATION-FIELDS(relation_id, relation_id) NESTED.


start = DATASET employees:READ-XML("FILE","D:\USERS\DANIELH\zadanie testowe\relacje2_zmiana\testInputFile2.xml","APPEND", ?, ?, ?, ?).

ASSIGN
typ = "FILE"
doPliku = "D:\USERS\DANIELH\Zadanie testowe\relacje2_zmiana\ZadanieeeWOW.json"
wartosc = TRUE.

zapisz = DATASET employees:WRITE-JSON(typ, doPliku, wartosc).

Continue reading...
 
Status
Not open for further replies.
Top