Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Converts a column containing a StructType into a XML string. Throws an exception, in the case of an unsupported type.
Syntax
from pyspark.sql import functions as sf
sf.to_xml(col, options=None)
Parameters
| Parameter | Type | Description |
|---|---|---|
col |
pyspark.sql.Column or str |
Name of column containing a struct. |
options |
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
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()
[Row(xml='<person>\n <age>2</age>\n <name>Alice</name>\n</person>')]