Home  >  Article  >  Backend Development  >  Code example of xml application in powerbuilder

Code example of xml application in powerbuilder

Y2J
Y2JOriginal
2017-04-25 14:59:272247browse

The data window in powerbuilder is really good. Work is basically done around it and it is very efficient. In the past few days, if I need to export xml files in projects, I use pb9 (the xml export and import function is from powerbuilder9.0 Added functions) made a demo to verify the feasibility

The sample file is as follows (the DTD will not be pasted, but a simple example will be given)

The 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 like this
order (sales order, including customer, date and other information)
orderdetail (sales order details, including Product, quantity and price information)
At this point, a discerning person may be able to see at a glance that there are some problems with the formatting of this xml. For example, this may be more reasonable.

The code is as follows:

<trans> <!--transdetail 这个节或许是多余的--> <order> <date/> <detail><!-- 明细是一个订单的一部分,不应该脱离订单头--> <orderdetail><product/></orderdetail> <orderdetail><product/></orderdetail> </detail> </order> <order> <date/> <detail> <orderdetail><product/></orderdetail> <orderdetail><product/></orderdetail> </detail> </order> </trans>

But I am a ZF department and cannot change it, so I have to do it badly.
The processing code in pb9: In fact, only three lines of code are written in pb9. The real code is actually only one line, which is to add a window. There is a data window and a button on it, and this line of code is written in the button, haha ​​
dw_export.save("c:\test.xml",xml!,false)
In fact, what we really need to deal with is the definition There are two data windows, mainly defining 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, if the conditions When the data has multiple rows, it is best to group it in SQL, otherwise the generated data will be repeated)
3. Right-click in the export/import template xml (hereinafter referred to as EITX) editing area and save as another name
4. Set the use template under data export to the template name you just saved.
The defined template is as follows:

The code is as follows:

<?xml version=~"1.0~" encoding=~"gb2312~" standalone=~"no~"?> <trans> <transdetail __pbband=~"detail~"><!-- 在EITX中的transdetail节上点右键选中"starts detail" [注1] --> <order> <date>order_date</date> </order> dw_detail <!-- 在EITX中的transdetail节上点右键选"add child"下的"datawindow control refrence" [注2] --> </transdetail> </trans>

Yes Two points need to be noted
[Note 1] This start detail will control the loop of data, so it needs to be selected, but each xml can only define one, and a problem will arise here. If my order header is looped, how can I repeat it? Let the order details cycle. The conclusion is that it cannot be realized in one data window and must be processed in separate data windows. This is Note 2
[Note 2] We need to insert a report in d_order, that is, d_orderdetail. The control list in d_order (the same as in the datawindow control refrence) is dw_detail (the default name is dw_1, I changed the name)
d_orderdetail (order detail data export, which is the data window referenced by report above, dw_detail, 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. Put data The use template under export is set to the template name you just saved
6a18328c58303c7e20e1d25369e13403
780ab39ca41c0688cbbbb8c417c3f74f
157f0b229ad5633f6c1b0a7cdc6ea6fc00c088fcdcf3bdd6b063129a514ea6b8
a719999c5224e00a42ab5e276e57a41bproduct_name1da18c4b98da1fc43a8786f07f99713f
a41d32f826faafc22f7b9211b5e2f6b0
bab239faed32331581b803189fdf21ef
[Note 3] Note that when we are in d_order When exporting xml, the xml statement and top node in d_orderdetail will be ignored
[Note 4] This place defines the orderdetail part, because an order may have multiple details, so we need to set it to start detail, also It's a cycle.
The final generated file is as follows

The code is as follows:

<trans> 
<transdetail> 
<order><date>20080101</date></order> 
<orderdetail><product>甲</product></orderdetail> 
<orderdetail><product>已</product></orderdetail> 
</transdetail> 
<transdetail> 
<order><date>20080102</date></order> 
<orderdetail><product>甲</product></orderdetail> 
<orderdetail><product>丙</product></orderdetail> 
</transdetail> 
</trans>


Note: If you are asked to design an xml interface file, please be sure to consider the convenience of the user

The above is the detailed content of Code example of xml application in powerbuilder. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn