powerbuilder(pb)中 xml的應(yīng)用一例_Xml教程
推薦:存儲于xml中需要的HTML轉(zhuǎn)義代碼在數(shù)據(jù)提交到數(shù)據(jù)庫之前的簡單HTML字符轉(zhuǎn)意,防止javascript惡意代碼,因?yàn)轫?xiàng)目中用到了輸出為xml,所以在輸出之前還要進(jìn)行二次轉(zhuǎn)意,把數(shù)據(jù)庫中之前加入的br轉(zhuǎn)義為正常。
示例文件如下(不貼DTD了,舉簡單例子說明一下)
復(fù)制代碼 代碼如下:hl5o.cn
<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(銷售訂單,包括客戶,日期等信息)
orderdetail(銷售訂單明細(xì),包括產(chǎn)品,數(shù)量及價格信息)
至此,可能明眼人一眼就能看出,這個xml的格式設(shè)置有些問題,例如這樣可能更加合理
復(fù)制代碼 代碼如下:hl5o.cn
<trans>
<!--transdetail 這個節(jié)或許是多余的-->
<order>
<date/>
<detail><!-- 明細(xì)是一個訂單的一部分,不應(yīng)該脫離訂單頭-->
<orderdetail><product/></orderdetail>
<orderdetail><product/></orderdetail>
</detail>
</order>
<order>
<date/>
<detail>
<orderdetail><product/></orderdetail>
<orderdetail><product/></orderdetail>
</detail>
</order>
</trans>
不過人家是ZF部門,改不了的,所以蹩腳也得做
pb9中的處理代碼:其實(shí)在pb9種只寫了三行代碼,真正的代碼其實(shí)只有一行,就是增加了一個窗口,上面放了一個數(shù)據(jù)窗口,一個按鈕,按鈕里寫了這么一行代碼,呵呵
dw_export.save("c:\test.xml",xml!,false)
其實(shí)真正要處理的是定義個兩個數(shù)據(jù)窗口,主要是定義他們的xml模版:
d_order(訂單頭數(shù)據(jù)出口,第二行代碼,可以在EITX中設(shè)置)
1.新建數(shù)據(jù)窗口(這里注意,如果如何條件的數(shù)據(jù)有多行時,最好在SQL中進(jìn)行g(shù)roup,否則生成的數(shù)據(jù)會有重復(fù))
3.在export/import template xml(下面簡稱EITX)編輯區(qū)點(diǎn)右鍵,save as另一個名字
4.把data export下的use template設(shè)置為你剛剛保存的模版名
定義好的模版如下所示:
復(fù)制代碼 代碼如下:hl5o.cn
<?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]這個start detail,將控制數(shù)據(jù)的循環(huán),所以需要選中,但是每個xml只能定義一個,這里就會產(chǎn)生一個問題,如果我訂單頭循環(huán)后,如何再讓訂單明細(xì)循環(huán),結(jié)論是,在一個數(shù)據(jù)窗口中無法實(shí)現(xiàn),必須分?jǐn)?shù)據(jù)窗口進(jìn)行處理,也就有了注2
[注2]我們需要在d_order中插入一個report,也就是d_orderdetail,在d_order中的control list(同在datawindow control refrence中相同)中就是dw_detail(默認(rèn)名稱是dw_1,我改名了)
d_orderdetail(訂單明細(xì)數(shù)據(jù)出口,也就是上面report,dw_detail引用的數(shù)據(jù)窗口,第三行代碼,可以在EITX中設(shè)置)
1.新建數(shù)據(jù)窗口
2.在export/import template xml(下面簡稱EITX)編輯區(qū)點(diǎn)右鍵,save as另一個名字
3.把data export下的use template設(shè)置為你剛剛保存的模版名
<?xml version=~"1.0~" encoding=~"gb2312~" standalone=~"no~"?>
<detail><!-- 這兒定義為orderdetail是沒用的,牽套時,會被忽略 [注3]-->
<orderdetail __pbband=~"detail~"><!-- [注4] -->
<product>product_name</product>
</orderdetail>
</detail>
[注3]注意,當(dāng)我們在d_order中導(dǎo)出xml時,d_orderdetail中的xml聲明和頂節(jié)點(diǎn)會被忽略
[注4]這個地方定義的就是orderdetail部分,因?yàn)橐粋訂單可能會有多條明細(xì)信息,所以我們需要設(shè)置為start detail,也就是循環(huán)。
最后生成的文件如下
復(fù)制代碼 代碼如下:hl5o.cn
<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ì)一個xml接口文件,請一定要考慮使用者的方便性
分享:讀大數(shù)據(jù)量的XML文件的讀取問題對于數(shù)據(jù)量較大的xml文件,使用xmlDocument讀取時,雖然支持XPath,查詢比較方便,但是需要先load,這樣就浪費(fèi)了內(nèi)存,使用起來速度比較慢。
相關(guān)Xml教程:
- xml創(chuàng)建節(jié)點(diǎn)(根節(jié)點(diǎn)、子節(jié)點(diǎn))
- WML開發(fā)教程之 WAP網(wǎng)站服務(wù)器配置方法
- WMLScript的語法基礎(chǔ)
- 收集的WML Script標(biāo)準(zhǔn)函數(shù)庫
- WML教程之文本框控件Input
- 無線標(biāo)記語言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)
- xml文件的結(jié)構(gòu)解讀
- 關(guān)于XSL - XSL教程
- 選擇模式 - XSL教程 - 2
- XPath入門 - XSL教程 - 3
- 匹配模式 - XSL教程 - 4
- 測試模式 - XSL教程 - 5
- 相關(guān)鏈接:
- 教程說明:
Xml教程-powerbuilder(pb)中 xml的應(yīng)用一例
。