You are viewing documentation about an older version (1.3.0). View latest version

snowflake.snowpark.functions.to_xml¶

snowflake.snowpark.functions.to_xml(e: ColumnOrName) → Column[source]¶

Converts any VARIANT value to a string containing the XML representation of the value. If the input is NULL, the result is also NULL.

Example::
>>> from snowflake.snowpark.types import VariantType, StructField, StructType
>>> from snowflake.snowpark import Row
>>> schema = StructType([StructField("a", VariantType())])
>>> df = session.create_dataframe([Row(a=10), Row(a='test'), Row(a={'a': 10, 'b': 20}), Row(a=[1, 2, 3])], schema=schema)
>>> df.select(to_xml(col("A")).as_("ans")).collect()
[Row(ANS='<SnowflakeData type="INTEGER">10</SnowflakeData>'), Row(ANS='<SnowflakeData type="VARCHAR">test</SnowflakeData>'), Row(ANS='<SnowflakeData type="OBJECT"><a type="INTEGER">10</a><b type="INTEGER">20</b></SnowflakeData>'), Row(ANS='<SnowflakeData type="ARRAY"><e type="INTEGER">1</e><e type="INTEGER">2</e><e type="INTEGER">3</e></SnowflakeData>')]
Copy