我们如何在Pyspark中读取非结构化XML文件

发布于 2025-01-28 22:02:27 字数 487 浏览 2 评论 0原文

<editors>
    <p poid="1232" class="odo">
        <person id="1232">Rob Jhon</person>
        <br /> **this text need to be read**
        <br />
        <title>Sto items:</title> **"this text need to be read"**
        <br />
        <title>Recent items:</title> **this text need to be read**

    </p>
</editors>

正如您在我的数据集中看到的那样,有一些未标记的字符串区域。 如何在Pyspark中正确读取此XML,以将此字符串字段视为列。

<editors>
    <p poid="1232" class="odo">
        <person id="1232">Rob Jhon</person>
        <br /> **this text need to be read**
        <br />
        <title>Sto items:</title> **"this text need to be read"**
        <br />
        <title>Recent items:</title> **this text need to be read**

    </p>
</editors>

As you see in my dataset there are some string areas which are not tagged.
How can i read this xml properly in pyspark to see this string field as a column as well.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔日梦未散 2025-02-04 22:02:27

如果XML是一个称为“ data.xml”的文件,则可以从:

import xml.etree.ElementTree as ET

tree = ET.parse("data.xml")
root = tree.getroot()

print(root[0][1].tail)

这对我有用。

我”

If xml is a file called "data.xml", you could start with:

import xml.etree.ElementTree as ET

tree = ET.parse("data.xml")
root = tree.getroot()

print(root[0][1].tail)

This works for me.

Works for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文