共用方式為


xpath_string

回傳第一個與 XPath 表達式相符的 XML 節點的文字內容。

語法

from pyspark.sql import functions as sf

sf.xpath_string(xml, path)

參數

參數 類型 Description
xml pyspark.sql.Column 或 str XML 欄位或欄位名稱。
path pyspark.sql.Column 或 str XPath 表達。

範例

from pyspark.sql import functions as sf
df = spark.createDataFrame([('<a><b>b</b><c>cc</c></a>',)], ['x'])
df.select(sf.xpath_string(df.x, sf.lit('a/c'))).show()
+--------------------+
|xpath_string(x, a/c)|
+--------------------+
|                  cc|
+--------------------+