Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
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>')]