---
title: xml (DataStreamReader)
description: "DataStreamReader.xml method in PySpark: 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."
canonical_url: https://docs.databricks.com/gcp/en/pyspark/reference/classes/datastreamreader/xml
---

# xml (DataStreamReader)

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:

```python
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()
```
