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.
Loads an XML file stream and returns the result as a DataFrame. If schema is not specified, the input schema is inferred from the data.
Syntax
xml(path, schema=None, **options)
Parameters
| Parameter | Type | Description |
|---|---|---|
path |
str | Path for the XML input. |
schema |
StructType or str, optional | Schema as a StructType or DDL-formatted string (for example, col0 INT, col1 DOUBLE). |
Returns
DataFrame
Examples
Write a DataFrame to XML and read it back as a stream:
import tempfile
import time
with tempfile.TemporaryDirectory(prefix="xml") as d:
spark.createDataFrame(
[{"age": 100, "name": "Hyukjin Kwon"}]
).write.mode("overwrite").option("rowTag", "person").xml(d)
q = spark.readStream.schema(
"age INT, name STRING"
).xml(d, rowTag="person").writeStream.format("console").start()
time.sleep(3)
q.stop()