回傳一個與 XPath 表達式相符的 XML 節點內的字串陣列。
語法
from pyspark.sql import functions as sf
sf.xpath(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>b1</b><b>b2</b><b>b3</b><c>c1</c><c>c2</c></a>',)], ['x'])
df.select(sf.xpath(df.x, sf.lit('a/b/text()'))).show()
+--------------------+
|xpath(x, a/b/text())|
+--------------------+
| [b1, b2, b3]|
+--------------------+