# 在 Python 中将 HTML 转换为 XML

> 在 Python 中将 HTML 转换为 XML。使用 Python 库 API 将 HTML 文件转换为 XMLs

Source: https://products.aspose.com/slides/zh/python-net/conversion/html-to-xml/
Updated: 2023-03-21



## 在 Python 中将 HTML 转换为 XML

[**Aspose.Slides for Python via .NET**](https://products.aspose.com/slides/zh/python-net/) 是一个强大的 Python 库，用于创建和操作演示文稿文件。此外，它提供了将 HTML 转换为 XML 的灵活方法。使用 **Aspose.Slides for Python via .NET**，任何开发人员或应用程序只需几行 Python 代码即可将 HTML 转换为 XML 文件。

作为现代文档处理 API，Aspose.Slides for Python 可快速将 HTML 文件导出为 XML 文件格式。 Aspose PowerPoint 库允许您将 HTML 转换为 XML 和许多其他文件格式

## 使用 Python 将 HTML 转换为 XML

要将 HTML 转换为 XML，您需要从 HTML 文件创建演示文稿并将其另存为 XML。

### 将 HTML 转换为 XML 的 Python 代码

```python

import aspose.slides as slides
import aspose.pydrawing as drawing

with slides.Presentation() as pres:
    with open(dataDir + "file.html", "rt") as stream:
        data = stream.read()
    pres.slides.add_from_html(data)
    for index in range(pres.slides.length):
        slide = pres.slides[index]

        with open("slide-{index}.xml".format(index = index), "wb") as file:
            slide.write_as_svg(file)

```

## 如何使用 Aspose.Slides for Python API 将 HTML 转换为 XML

这些是在 Python 中将 HTML 转换为 XML 的步骤。

安装 [**Aspose.Slides for Python via .NET**](https://products.aspose.com/slides/zh/python-net/)。

将库引用（导入库）添加到您的 Python 项目。

在 Python 中打开源 HTML 文件。

将结果保存为 XML 文件。

## 将 HTML 转换为其他支持的格式
