to_xml
Converts a column containing a StructType into a XML string. Throws an exception, in the case of an unsupported type.
Syntax
Python
from pyspark.sql import functions as sf
sf.to_xml(col, options=None)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| Name of column containing a struct. |
| dict, optional | Options to control converting. Accepts the same options as the XML datasource. |
Returns
pyspark.sql.Column: a XML string converted from given StructType.
Examples
Python
from pyspark.sql import Row, functions as sf
data = [(1, Row(age=2, name='Alice'))]
df = spark.createDataFrame(data, ("key", "value"))
df.select(sf.to_xml(df.value, {'rowTag':'person'}).alias("xml")).collect()
Output
[Row(xml='<person>\n <age>2</age>\n <name>Alice</name>\n</person>')]