xml (DataFrameReader)
XMLファイルを読み込み、結果をDataFrameとして返します。schemaが指定されていない場合、この関数は入力スキーマを決定するために一度入力を読み込みます。
構文
xml(path, schema=None, **options)
パラメーター
パラメーター | Type | 説明 |
|---|---|---|
| 文字列、リスト、またはRDD | 1つ以上の入力パス、またはXML行を格納する文字列のRDD。 |
| 構造体型またはstr(オプション) | オプションの入力スキーマは、 |
戻り値
DataFrame
例
DataFrameをXMLファイルに書き込み、それを読み込む。
Python
import tempfile
with tempfile.TemporaryDirectory(prefix="xml") as d:
spark.createDataFrame(
[{"age": 100, "name": "Alice"}]
).write.mode("overwrite").option("rowTag", "person").format("xml").save(d)
spark.read.option("rowTag", "person").xml(d).show()
# +---+------------+
# |age| name|
# +---+------------+
# |100|Alice|
# +---+------------+