Python使用Schema-Location生成XML

时间:2015-06-03 19:48:35

标签: python xml xsd

我如何创建这样的XML:

<urlset xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
    <url>
        <loc>http://...</loc>
    </url>
</urlset>

如何使用xml.etree添加xsi:schemaLocation?这是我的代码:

urlset = ET.Element("urlset")
for url in self.urls:
    url = ET.SubElement(urlset, "url")
    ET.SubElement(url, "loc").text = url.loc
self.tree = ET.ElementTree(urlset)
self.tree.write(path)

是否有一种简单的方法来添加这样的属性?

0 个答案:

没有答案