1 回答
TA贡献1793条经验 获得超6个赞
如果你想从 Azure blob 中读取 xml 文件,我们可以使用 packageazure.storage.blob来实现它。
例如
我的 xml 文件
<?xml version="1.0"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Panama">
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>
代码
import xml.etree.ElementTree as ET
from azure.storage.blob import BlobServiceClient
connection_string='<your storage account connection string>'
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = blob_service_client.get_blob_client(container="test", blob="data.xml")
downloader = blob_client.download_blob()
root = ET.fromstring(downloader.content_as_text())
for neighbor in root.iter('neighbor'):
print(neighbor.attrib)
添加回答
举报