Application of XML in PowerBuilder (PB) Example _xml

Source: Internet
Author: User

sample files are as follows (no DTD, just a simple example)

Copy Code code 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 table should be designed like this
Order (sales orders, including information about customers, dates, etc.)
OrderDetail (sales order details, including product, quantity and price information)

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

<trans>
<!--transdetail This section may be redundant-->
<order>
<date/>
<detail><!--Detail is part of an order and should not be detached 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 it's the ZF department, and it's not going to change, so it's lame.

PB9 in the processing code: In fact, the PB9 only wrote three lines of code, the real code in fact only one line, is added a window, above put a data window, a button, the button wrote a line of code, hehe
Dw_export.save ("C:\test.xml", Xml!,false)

The real deal is to define a two-data window, primarily to define their XML templates:
D_order (order header data exit, second line of code, can be set in EITX)
1. Create a new Data window (note here that if you have multiple rows of data with a condition, it is best to group in SQL, otherwise the resulting data will be duplicated)
3. In Export/import template XML (hereinafter referred to eitx) edit area right click, Save as another name
4. Set the use template under data Export to the template name you just saved
The templates that are defined are as follows:
Copy Code code as follows:

<?xml version=~ "1.0~" encoding=~ "gb2312~" standalone=~ "no~"?>
<trans>
<transdetail __pbband=~ "detail~" ><!--right-click 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 of EITX to select "DataWindow control refrence" under "Add Child" [Note 2]-->
</transdetail>
</trans>

There are two points to be aware of
[Note 1] This start detail, will control the data loop, so you need to select, but each XML can only define one, here will be a problem, if I order the first loop, how to let the Order details loop, the conclusion is that in a data window can not be implemented, must be processed in a data window, And there's a note 2.
[Note 2] we need to insert a d_order in the D_orderdetail, which is the same as the control list in D_order (same as in the DataWindow control refrence) dw_detail (The default name is Dw_1, I renamed it)

D_orderdetail (Order detail data exit, that is, the above Report,dw_detail referenced data window, the third line of code, can be set in EITX)
1. New Data window
2. In Export/import template XML (hereinafter referred to eitx) edit area right click, 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><!--here defined as OrderDetail is useless, when the sleeve is ignored [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 the top node in the D_orderdetail are ignored
[Note 4] This place is defined as the OrderDetail part, because an order may have more than one detail, so we need to set the start detail, which is the loop.

The resulting file is as follows
Copy Code code as follows:

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

Note: If you want to design an XML interface file, be sure to consider the convenience of the user

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.