国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Python > 正文

使用Python下的XSLT API進(jìn)行web開(kāi)發(fā)的簡(jiǎn)單教程

2020-02-23 00:45:02
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

Kafka 樣式的 soap 端點(diǎn)

Christopher Dix 所開(kāi)發(fā)的“Kafka — XSL SOAP 工具箱”(請(qǐng)參閱 參考資料)是一種用于構(gòu)造 SOAP 端點(diǎn)的 XSLT 框架。它只涵蓋了 SOAP 1.1,但 Kafka 端點(diǎn)演示了傳遞 UserLand SOAP 驗(yàn)證器(UserLand SOAP Validator)的能力,并且根據(jù) SOAP 1.2 對(duì)它進(jìn)行更新似乎并不太困難。 清單 1展示了一個(gè)樣本 Kafka 端點(diǎn):求兩數(shù)之和的 SOAP 服務(wù)器(一個(gè)典型而簡(jiǎn)單的 SOAP 樣本)。

清單 1. 求兩數(shù)之和的 Kafka SOAP 端點(diǎn)

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:method="http://www.topxml.com/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  <!-- add.xsl : Kafka SOAP Endpoint Example, with modifications -->  <!-- Import soap.xsl to use the framework -->  <xsl:import href="kafka/soap.xsl"/>  <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes"/>  <!-- Define the global variables for the framework -->  <xsl:variable name="Method">Add</xsl:variable>  <xsl:variable name="MethodNS">http://www.topxml.com/</xsl:variable>  <!-- Add : Add two numbers and return the sum -->  <!-- Function Add( A as Double, B as Double ) as Double -->  <xsl:template name="ProcessPayload">   <xsl:param name="Payload"/>   <xsl:for-each select="$Payload">     <!-- This is how to retrieve parameters from the input -->     <xsl:variable name="A" select="number(A|method:A)"/>     <xsl:variable name="B" select="number(B|method:B)"/>     <!-- The WriteParameter template takes the qualified name       for a response parameter as well as its value and       a QName specifying the tpe (for the xsi:type attribute) -->     <xsl:call-template name="WriteParameter">      <xsl:with-param name="p" select="'Result'"/>      <xsl:with-param name="v" select="$A + $B"/>      <xsl:with-param name="t" select="'xsd:double'"/>     </xsl:call-template>   </xsl:for-each>  </xsl:template>  </xsl:stylesheet>

XSLT 端點(diǎn)導(dǎo)入 SOAP 框架(文件 kafka/soap.xsl),然后設(shè)置該框架將要使用的參數(shù),并設(shè)置它在處理構(gòu)成 SOAP 消息的整個(gè) XML 文檔的過(guò)程中將要分派的模板。全局變量 Method 和 MethodNS 聲明了組成消息的 XML 元素。在處理完 SOAP 信封之后,該框架調(diào)用 ProcessPayload 模板,該模板傳入了 XML 主體的有效負(fù)載。 xsl:for-each 是將上下文切換成想要的節(jié)點(diǎn)的標(biāo)準(zhǔn)技巧。參數(shù) A 和 B 是使用簡(jiǎn)單 XPaths 從這個(gè)元素讀取的,而框架被再次調(diào)用以幫助寫(xiě)出響應(yīng)參數(shù)。 WriteParameter 模板讓您指定元素名稱、數(shù)據(jù)類型和每個(gè)輸出參數(shù)的值。本示例中的響應(yīng)值是將兩個(gè)輸入?yún)?shù)相加所得的結(jié)果。

將這個(gè)端點(diǎn)部署為服務(wù)器相當(dāng)于設(shè)置一個(gè) HTTP 偵聽(tīng)器。Python 的 BaseHTTPServer 模塊向您提供了所需的機(jī)制,能夠輕而易舉地處理該協(xié)議的 HTTP 部分。請(qǐng)參閱 清單 2。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 贵州省| 绥滨县| 通许县| 内丘县| 土默特右旗| 获嘉县| 瓮安县| 兴仁县| 永城市| 壶关县| 昭平县| 桐乡市| 兰州市| 原平市| 镇江市| 信丰县| 德清县| 工布江达县| 漯河市| 通州市| 科技| 海南省| 准格尔旗| 洞头县| 县级市| 铜川市| 云林县| 巴楚县| 当阳市| 施甸县| 镇巴县| 阜康市| 五峰| 吉首市| 郴州市| 文水县| 颍上县| 德钦县| 文成县| 福清市| 林口县|