通过


xpath_string

返回与 XPath 表达式匹配的第一个 xml 节点的文本内容。

Syntax

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|
+--------------------+