メインコンテンツまでスキップ

Xパス

XPath 式に一致する xml ノード内の値の文字列配列を返します。

構文

Python
from pyspark.sql import functions as sf

sf.xpath(xml, path)

パラメーター

パラメーター

Type

説明

xml

pyspark.sql.Column または文字列

XML 列または列名。

path

pyspark.sql.Column または文字列

XPath 式。

Python
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()
Output
+--------------------+
|xpath(x, a/b/text())|
+--------------------+
| [b1, b2, b3]|
+--------------------+