Skip to main content

xpath_number

Returns a double value, the value zero if no match is found, or NaN if a match is found but the value is non-numeric.

Syntax

Python
from pyspark.sql import functions as sf

sf.xpath_number(xml, path)

Parameters

Parameter

Type

Description

xml

pyspark.sql.Column or str

XML column or column name.

path

pyspark.sql.Column or str

XPath expression.

Examples

Python
import pyspark.sql.functions as sf
spark.createDataFrame(
[('<a><b>1</b><b>2</b></a>',)], ['x']
).select(sf.xpath_number('x', sf.lit('sum(a/b)'))).show()
Output
+-------------------------+
|xpath_number(x, sum(a/b))|
+-------------------------+
| 3.0|
+-------------------------+