我刚开始使用lxml基础知识而且我遇到了命名空间:我需要生成一个像这样的xml:
xmlns:bldg="http://www.opengis.net/citygml/building/2.0"
1000
通过使用以下代码:
from lxml import etree
cityModel = etree.Element("cityModel")
cityObject = etree.SubElement(cityModel, "cityObjectMember")
bldg = etree.SubElement(cityObject, "{http://schemas.opengis.net/citygml/building/2.0/building.xsd}bldg")
function = etree.SubElement(bldg, "{bldg:}function")
function.text = "1000"
print etree.tostring(cityModel, pretty_print=True)
我明白了:
1000
这与我想要的完全不同,我的软件也没有解析它.
如何获得正确的xml?