Question; XML element order for complex elements with prodat

Posted by Admin on 23-Apr-2007 04:16

Hello,

How can i influence the order of complex elements resulting from xml-write based on a prodataset ?

Example; I have two temptables, lets say one for orders and one for orderlines. I define the relation in a prodataset.

In my temptable for orders i define 3 fields O1,O2,O3, and in the temptable for orderlines i define a couple fields also.

Now the resulting XML will always be in the order :

But it would be nice to have the option to assign a value so that it will not write any element data for that field.

All Replies

Posted by Thomas Mercer-Hursh on 23-Apr-2007 11:55

Look up the Write-XML() method and NESTED

To get the optional field, I am sure that you will either have to post-filter the results or write your own equivalent of Write-XML().

Posted by Admin on 26-Apr-2007 09:33

Hmm thats not exactly what i meant

I know how the WRITE-XML works and the NESTED option. But i think its not possible to build an XML with a complex elements in the middle between simple elements. You can only put complex elements at the end (still nested and with nested you can put other complex elements in the previous one again also, works fine, but always after the simple elements. So now i wrote my own WRITE-XML version where i can do that.

Im a bit dissapointed in the limited abilities of mapping XML to datasets/temptables with WRITE-XML and READ-XML, unless the xml is extremely simple it seems pretty useless to me. Even the commandline tool wont generate include files for most schema's and give an errormessage saying something like cant map schema to dataset...So its back to writing it yrself with the sax reader/writer...

Or am i completely wrong ?

Posted by Thomas Mercer-Hursh on 26-Apr-2007 10:43

When I first heard about read- and write-xml methods, I thought cool, but it took me about 15 minutes to decide that there were notable limitations and it was awfully easy to write on oneself. Indeed, if one were properly using code generation, one wouldn't even have to do that. One of the pieces that got me was the header it insists on putting on. If one is trying to serialize a collection, then one has to strip out that header on all of the components before assembling it.

Frankly, it seems like one of those things where, by the time you put enough options on to cover all the bases, it would be so complex to use that one might as well just write the code.

Posted by Admin on 26-Apr-2007 15:26

How can i define it so that the xml would be like :

......

line>

I guess you want a more realistic version like:

when there is no DATA-RELATION between the temp-tables in the dataset.

Posted by Admin on 27-Apr-2007 07:31

Theo, i think yr missing the point.

The situation that u call more realistic is easy to make. But you show only tables in your example, and dont show any fields. Nesting tables isnt the problem. The problem is i cant state between which fields in table 1 i want to place table2.

example :

Example :

(i didnt testrun this, its just typing text)

define temp-table ttHeadline no-undo

FIELD ttHeadline_id AS INTEGER XML-NODE-TYPE "HIDDEN"

FIELD headfield1 AS CHARACTER

FIELD headfield2 AS CHARACTER

FIELD headfield3 AS CHARACTER

index ttHeadline_id is primary unique ttHeadline_id.

define temp-table ttSubine no-undo

FIELD ttSubline_id AS INTEGER XML-NODE-TYPE "HIDDEN"

FIELD ttHeadline_id AS INTEGER XML-NODE-TYPE "HIDDEN"

FIELD subfield1 AS CHARACTER

FIELD subfield2 AS CHARACTER

FIELD subfield3 AS CHARACTER

index ttSubline_id is primary unique ttSubline_id.

define dataset dsMydataset NAMESPACE-URI "http://something/somethingmore"

for ttHeadline , ttSubline

DATA-RELATION FOR ttHeadline , ttSubline RELATION-FIELDS (ttHeadline.ttHeadline_id, ttSubine.ttHeadline_id) NESTED

.

If you take this example code, WRITE-XML will generate something like this :

Without the nested option it would place ttsubline below ttheadline and not within, but thats not the problem here.

Then again, i already gave up on WRITE-XML, best way is to do make yr own WRITE-XML

Posted by Thomas Mercer-Hursh on 27-Apr-2007 10:45

So, would it be accurate to say that your problem is that in your case, the second table is conceptually a child of one of the fields in the first table, rather than a child of the record as a whole?

Posted by Admin on 28-Apr-2007 03:52

nopes its not a child of a field, normal child of table. But just cant say where in the xml result the subtable should be placed. If in the headline table you change the position of field2 and field 3, then in the output xml these are also in changed order. But you cant specify where in the output the subtable is placed.

Basicly what i wanna be able to do is say :

define temp-table ttHeadline no-undo

FIELD ttHeadline_id AS INTEGER XML-NODE-TYPE "HIDDEN"

FIELD headfield1 AS CHARACTER

FIELD headfield2 AS CHARACTER

FIELD dummy AS CHARACTER XML-NODE-TYPE "HIDDEN" HELP "INSERT CHILD TABLE ttSubline here"

FIELD headfield3 AS CHARACTER

index ttHeadline_id is primary unique ttHeadline_id.

Posted by Admin on 28-Apr-2007 08:52

Basicly what i wanna be able to do is say :

define temp-table ttHeadline no-undo

FIELD ttHeadline_id AS INTEGER XML-NODE-TYPE

"HIDDEN"

FIELD headfield1 AS CHARACTER

FIELD headfield2 AS CHARACTER

FIELD dummy AS CHARACTER XML-NODE-TYPE "HIDDEN"

HELP "INSERT CHILD TABLE ttSubline here"

FIELD headfield3 AS CHARACTER

index ttHeadline_id is primary unique ttHeadline_id.

Have you tried defining an XML-schema upfront and let the write-xml of the dataset use it? It should obey the schema...

Posted by Thomas Mercer-Hursh on 28-Apr-2007 10:51

What I am trying to get clear is why you want the subtable at that particular position. I.e., what is "natural" or "appropriate" about it being there rather than somewhere else?

Posted by Admin on 29-Apr-2007 03:28

The reason is simple; we already have quite a few xml messages in a certain layout; but the code used for it wasnt optimal so im looking at ways to re-write the code without changing our existing messages so our customers wont experience any changes except performace improvement.

Posted by Admin on 29-Apr-2007 03:33

Theo,

Sounds good, but if i look at WRITE-XML i can only enter schema parameters to generate a schema or write a schema location in the xml.

But you're saying that i can define a dataset with temptables and somehow tell WRITE-XML to use a schema file ??

Can you post a brief example of how to do that ?

Posted by Admin on 30-Apr-2007 03:36

But you're saying that i can define a dataset with

temptables and somehow tell WRITE-XML to use a schema

file ??

Can you post a brief example of how to do that ?

I can't test this, since I'm not actively programming ABL anymore, but as far as I can see, you should use READ-XML-SCHEMA() first to load an XML-schema and associate it with the ProDataSet. Next when you write the XML it should respect the schema. You can use the schema reference in the WRITE-XML to point to an external schema for the users of your XML. That's something else but it should of course match the schema the PDS is using

Posted by Admin on 30-Apr-2007 06:27

Well as far as i can see, it doesnt work like that

Would be nice, but with write-xml u cant specify which schema to obey, it takes a schema definition from the structure of the temp-tables. the readxml schema can only verify a schema against a static defined dataset/temptable, or create a dynamic one based on a xsd. And even then, there are many schema options that dont work with the read schema...

Ah well, tnx for trying

This thread is closed