【问题标题】:How to modify the XML file using Python?如何使用 Python 修改 XML 文件?
【发布时间】:2016-10-13 12:43:50
【问题描述】:

实际上我已经获得了 XML 字符串并解析字符串以从中获取属性。现在我希望我的 XML 文件更改,查看属性。就像我想改变笔画的颜色一样。有什么办法吗?我将如何更改然后再次保存文件。

import requests
from xml.dom import minidom

response = requests.get('http://localhost:8080/geoserver/rest/styles/pakistan.sld',
                        auth=('admin', 'geoserver'))
fo=open("/home/adeel/Desktop/untitled1/yes.xml", "wb")
fo.write(response.text)
fo.close()

xmldoc = minidom.parse('yes.xml')
itemlist = xmldoc.getElementsByTagName('CssParameter')
print "Len : ", len(itemlist)
#print "Attribute Name : ", \
itemlist[0].attributes['name'].value
print "Text : ", itemlist[0].firstChild.nodeValue

for s in itemlist :
    print "Attribute Name : ", s.attributes['name'].value
    print "Text : ", s.firstChild.nodeValue

【问题讨论】:

    标签: python xml django geoserver


    【解决方案1】:

    您可能应该通读SLD Cook book 以获取有关如何更改 SLD 中线条颜色等内容的提示。更改后,您需要创建 PUT request 以将文件放回服务器上。

    【讨论】:

    • 是的,我已经弄清楚了。无论如何感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    • 1970-01-01
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    相关资源
    最近更新 更多