Read non-list xml into temp-table

Posted by Johan Vergeer on 17-Oct-2017 05:05

When reading some xml into a temp-table or dataset it usually is not a problem. 

But there are cases when the data is not in a list, but in the top level of the xml file. 

When this is my temp-table:

DEF TEMP-TABLE ttCustomer NO-UNDO

XML-NODE-NAME "customerItem"

FIELD customer_id AS INT

FIELD firstname AS CHAR

FIELD lastname AS CHAR.

This will work

And this will not

Is there a way to tell the temp-table that there is only one item, and not a list so it can be picked up?

If this is not possible, what would be the second best option?

Posted by Torben on 17-Oct-2017 07:50

I'm able to read this xml:

<?xml version="1.0"?>
<customerInfo xmlns:xsi="www.w3.org/.../XMLSchema-instance">
  <customer_id>28</customer_id>
  <email>me@company.com</email>
  <firstname>Given</firstname>
  <lastname>Family</lastname>
</customerInfo>

Using following ABL:
DEFINE TEMP-TABLE customerInfo NO-UNDO
   FIELD customer_id AS INTEGER
   FIELD email AS CHARACTER
   FIELD firstname AS CHARACTER 
   FIELD lastname AS CHARACTER 
   .
DEFINE VARIABLE LC AS LONGCHAR NO-UNDO.
LC = '<?xml version="1.0"?>
<customerInfo xmlns:xsi="www.w3.org/.../XMLSchema-instance">
  <customer_id>28</customer_id>
  <email>me@company.com</email>
  <firstname>Given</firstname>
  <lastname>Family</lastname>
</customerInfo>'.

BUFFER customerInfo:READ-XML("LONGCHAR", LC, "MERGE", ?, ?).

in OE 11.7.1

All Replies

Posted by tpavlovic on 17-Oct-2017 05:13

What is the difference between those two .xmls? You posted exactly the same picture twice.

Posted by Johan Vergeer on 17-Oct-2017 05:32

You are right.

I changed it so the pictures are different.

Posted by Torben on 17-Oct-2017 07:50

I'm able to read this xml:

<?xml version="1.0"?>
<customerInfo xmlns:xsi="www.w3.org/.../XMLSchema-instance">
  <customer_id>28</customer_id>
  <email>me@company.com</email>
  <firstname>Given</firstname>
  <lastname>Family</lastname>
</customerInfo>

Using following ABL:
DEFINE TEMP-TABLE customerInfo NO-UNDO
   FIELD customer_id AS INTEGER
   FIELD email AS CHARACTER
   FIELD firstname AS CHARACTER 
   FIELD lastname AS CHARACTER 
   .
DEFINE VARIABLE LC AS LONGCHAR NO-UNDO.
LC = '<?xml version="1.0"?>
<customerInfo xmlns:xsi="www.w3.org/.../XMLSchema-instance">
  <customer_id>28</customer_id>
  <email>me@company.com</email>
  <firstname>Given</firstname>
  <lastname>Family</lastname>
</customerInfo>'.

BUFFER customerInfo:READ-XML("LONGCHAR", LC, "MERGE", ?, ?).

in OE 11.7.1

This thread is closed