SoFunction
Updated on 2025-03-02

An example of application of xml in powerbuilder(pb)

The sample file is as follows (no DTD is posted, please give a simple example to illustrate)

Copy the codeThe code is as follows:

<trans>
<transdetail>
<order><date/></order>
<orderdetail><product/></orderdetail>
<orderdetail><product/></orderdetail>
</transdetail>
<transdetail>
<order><date/></order>
<orderdetail><product/></orderdetail>
<orderdetail><product/></orderdetail>
</transdetail>
</trans>

My table structure, I think everyone's tables should be designed in this way.
order (sales order, including customer, date, etc.)
orderdetail (sales order details, including product, quantity and price information)

At this point, it may be possible for anyone with a discerning eye to see that there are some problems with the formatting of this xml, for example, this may be more reasonable.
Copy the codeThe code is as follows:

<trans>
<!--transdetail This section may be redundant->
<order>
<date/>
<detail><!-- Details are part of an order and should not be separated from the order header-->
<orderdetail><product/></orderdetail>
<orderdetail><product/></orderdetail>
</detail>
</order>
<order>
<date/>
<detail>
<orderdetail><product/></orderdetail>
<orderdetail><product/></orderdetail>
</detail>
</order>
</trans>

But they are in the ZF department and cannot change it, so they have to do it even if they are bad.

Processing code in pb9: In fact, in pb9, only three lines of code were written. The real code actually had only one line, which was added a window, a data window and a button, and a line of code was written in the button. Haha
dw_export.save("c:\",xml!,false)

In fact, what we really need to deal with is to define two data windows, mainly to define their xml templates:
d_order (order header data export, second line of code, can be set in EITX)
1. Create a new data window (note here that if there are multiple rows of data in the condition, it is best to group it in SQL, otherwise the generated data will be duplicated)
3. Right-click in the export/import template xml (hereinafter referred to as EITX) editing area, save as another name
4. Set the use template under data export to the template name you just saved
The defined template looks like this:
Copy the codeThe code is as follows:

<?xml version=~"1.0~" encoding=~"gb2312~" standalone=~"no~"?>
<trans>
<transdetail __pbband=~"detail~"><!-- Right-click on the transdetail section in EITX to select "starts detail" [Note 1] -->
<order>
<date>order_date</date>
</order>
dw_detail <!-- Right-click on the transdetail section in EITX and select "datawindow control refrence" under "add child" [Note 2] -->
</transdetail>
</trans>

There are two things to note
[Note 1] This start detail controls the loop of data, so it needs to be selected, but only one can be defined per xml, which will cause a problem here. If I loop the order header, how to loop the order details again. The conclusion is that it cannot be implemented in a data window and must be processed in a data window, so there will be Note 2
[Note 2] We need to insert a report in d_order, that is, d_orderdetail. In the control list in d_order (the same as in datawindow control reflection) it is dw_detail (the default name is dw_1, I changed the name)

d_orderdetail (order details data export, that is, the data window referenced by report, dw_detail above, the third line of code, can be set in EITX)
1. Create a new data window
2. Right-click in the export/import template xml (hereinafter referred to as EITX) editing area, save as another name
3. Set the use template under data export to the template name you just saved
<?xml version=~"1.0~" encoding=~"gb2312~" standalone=~"no~"?>
<detail><!-- It is useless to define it as orderdetail. It will be ignored when pulling a trap [Note 3]-->
<orderdetail __pbband=~"detail~"><!-- [Note 4] -->
<product>product_name</product>
</orderdetail>
</detail>
[Note 3] Note that when we export xml in d_order, the xml declaration and top node in d_orderdetail will be ignored
[Note 4] This place defines the orderdetail part. Because an order may have multiple detailed information, we need to set it to start detail, that is, loop.

The last generated file is as follows
Copy the codeThe code is as follows:

<trans>
<transdetail>
<order><date>20080101</date></order>
<orderdetail><product>A</product></orderdetail>
<orderdetail><product>already</product></orderdetail>
</transdetail>
<transdetail>
<order><date>20080102</date></order>
<orderdetail><product>A</product></orderdetail>
<orderdetail><product>C</product></orderdetail>
</transdetail>
</trans>

Note: If you are asked to design an XML interface file, please be sure to consider the user's convenience.