xpath
Renvoie un tableau de chaînes de valeurs au sein des nœuds XML qui correspondent à l'expression XPath.
Syntaxe
Python
from pyspark.sql import functions as sf
sf.xpath(xml, path)
parameter
parameter | Type | Description |
|---|---|---|
|
| Colonne XML ou nom de colonne. |
|
| Expression XPath. |
Exemples
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]|
+--------------------+