powerbuilder(pb)中 xml的應(yīng)用一例
更新時(shí)間:2009年06月22日 12:50:30 作者:
powerbuilder中的數(shù)據(jù)窗口真是好的不得了,工作基本上都是圍繞它做,很高效,這幾天項(xiàng)目上需要用導(dǎo)出xml文件,就用pb9(xml導(dǎo)出導(dǎo)入功能是從powerbuilder9.0增加的功能)做了一個(gè)demo以驗(yàn)證可行性
示例文件如下(不貼DTD了,舉簡(jiǎn)單例子說(shuō)明一下)
復(fù)制代碼 代碼如下:
<trans>
<transdetail>
<order><date/></order>
<orderdetail><product/></orderdetail>
<orderdetail><product/></orderdetail>
</transdetail>
<transdetail>
<order><date/></order>
<orderdetail><product/></orderdetail>
<orderdetail><product/></orderdetail>
</transdetail>
</trans>
我的表結(jié)構(gòu),我想大家的表也應(yīng)該都是這樣設(shè)計(jì)的
order(銷(xiāo)售訂單,包括客戶,日期等信息)
orderdetail(銷(xiāo)售訂單明細(xì),包括產(chǎn)品,數(shù)量及價(jià)格信息)
至此,可能明眼人一眼就能看出,這個(gè)xml的格式設(shè)置有些問(wèn)題,例如這樣可能更加合理
復(fù)制代碼 代碼如下:
<trans>
<!--transdetail 這個(gè)節(jié)或許是多余的-->
<order>
<date/>
<detail><!-- 明細(xì)是一個(gè)訂單的一部分,不應(yīng)該脫離訂單頭-->
<orderdetail><product/></orderdetail>
<orderdetail><product/></orderdetail>
</detail>
</order>
<order>
<date/>
<detail>
<orderdetail><product/></orderdetail>
<orderdetail><product/></orderdetail>
</detail>
</order>
</trans>
不過(guò)人家是ZF部門(mén),改不了的,所以蹩腳也得做
pb9中的處理代碼:其實(shí)在pb9種只寫(xiě)了三行代碼,真正的代碼其實(shí)只有一行,就是增加了一個(gè)窗口,上面放了一個(gè)數(shù)據(jù)窗口,一個(gè)按鈕,按鈕里寫(xiě)了這么一行代碼,呵呵
dw_export.save("c:\test.xml",xml!,false)
其實(shí)真正要處理的是定義個(gè)兩個(gè)數(shù)據(jù)窗口,主要是定義他們的xml模版:
d_order(訂單頭數(shù)據(jù)出口,第二行代碼,可以在EITX中設(shè)置)
1.新建數(shù)據(jù)窗口(這里注意,如果如何條件的數(shù)據(jù)有多行時(shí),最好在SQL中進(jìn)行g(shù)roup,否則生成的數(shù)據(jù)會(huì)有重復(fù))
3.在export/import template xml(下面簡(jiǎn)稱(chēng)EITX)編輯區(qū)點(diǎn)右鍵,save as另一個(gè)名字
4.把data export下的use template設(shè)置為你剛剛保存的模版名
定義好的模版如下所示:
復(fù)制代碼 代碼如下:
<?xml version=~"1.0~" encoding=~"gb2312~" standalone=~"no~"?>
<trans>
<transdetail __pbband=~"detail~"><!-- 在EITX中的transdetail節(jié)上點(diǎn)右鍵選中"starts detail" [注1] -->
<order>
<date>order_date</date>
</order>
dw_detail <!-- 在EITX中的transdetail節(jié)上點(diǎn)右鍵選"add child"下的"datawindow control refrence" [注2] -->
</transdetail>
</trans>
有兩點(diǎn)需要注意
[注1]這個(gè)start detail,將控制數(shù)據(jù)的循環(huán),所以需要選中,但是每個(gè)xml只能定義一個(gè),這里就會(huì)產(chǎn)生一個(gè)問(wèn)題,如果我訂單頭循環(huán)后,如何再讓訂單明細(xì)循環(huán),結(jié)論是,在一個(gè)數(shù)據(jù)窗口中無(wú)法實(shí)現(xiàn),必須分?jǐn)?shù)據(jù)窗口進(jìn)行處理,也就有了注2
[注2]我們需要在d_order中插入一個(gè)report,也就是d_orderdetail,在d_order中的control list(同在datawindow control refrence中相同)中就是dw_detail(默認(rèn)名稱(chēng)是dw_1,我改名了)
d_orderdetail(訂單明細(xì)數(shù)據(jù)出口,也就是上面report,dw_detail引用的數(shù)據(jù)窗口,第三行代碼,可以在EITX中設(shè)置)
1.新建數(shù)據(jù)窗口
2.在export/import template xml(下面簡(jiǎn)稱(chēng)EITX)編輯區(qū)點(diǎn)右鍵,save as另一個(gè)名字
3.把data export下的use template設(shè)置為你剛剛保存的模版名
<?xml version=~"1.0~" encoding=~"gb2312~" standalone=~"no~"?>
<detail><!-- 這兒定義為orderdetail是沒(méi)用的,牽套時(shí),會(huì)被忽略 [注3]-->
<orderdetail __pbband=~"detail~"><!-- [注4] -->
<product>product_name</product>
</orderdetail>
</detail>
[注3]注意,當(dāng)我們?cè)赿_order中導(dǎo)出xml時(shí),d_orderdetail中的xml聲明和頂節(jié)點(diǎn)會(huì)被忽略
[注4]這個(gè)地方定義的就是orderdetail部分,因?yàn)橐粋€(gè)訂單可能會(huì)有多條明細(xì)信息,所以我們需要設(shè)置為start detail,也就是循環(huán)。
最后生成的文件如下
復(fù)制代碼 代碼如下:
<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>
注:如果讓你設(shè)計(jì)一個(gè)xml接口文件,請(qǐng)一定要考慮使用者的方便性
您可能感興趣的文章:
相關(guān)文章
Xml簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
XML 只是基于普通文本,但卻提供了幾乎可以在任何兩個(gè)應(yīng)用程序間共享數(shù)據(jù)的方式2017-08-08
使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁(yè)的方法
使用Spry輕松將XML數(shù)據(jù)顯示到HTML頁(yè)的方法...2007-05-05
讀大數(shù)據(jù)量的XML文件的讀取問(wèn)題
對(duì)于數(shù)據(jù)量較大的xml文件,使用xmlDocument讀取時(shí),雖然支持XPath,查詢比較方便,但是需要先load,這樣就浪費(fèi)了內(nèi)存,使用起來(lái)速度比較慢。2009-11-11
氣象 XML 數(shù)據(jù)源應(yīng)用程序開(kāi)發(fā)指南-內(nèi)容目錄
氣象 XML 數(shù)據(jù)源應(yīng)用程序開(kāi)發(fā)指南-內(nèi)容目錄...2007-02-02

