在python minidom中更改名称空间
我有以下xml:在python minidom中更改名称空间,python,xml,dom,minidom,Python,Xml,Dom,Minidom,我有以下xml: <gml:FeatureCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:aqd="http://www.exampleURI.com/AQD" xmlns:base="urn:x-inspire:specification:gmlas:BaseTypes:3.2" xmlns:gmd=
<gml:FeatureCollection xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:aqd="http://www.exampleURI.com/AQD"
xmlns:base="urn:x-inspire:specification:gmlas:BaseTypes:3.2"
xmlns:gmd="http://www.isotc211.org/2005/gmd"
xmlns:gco="http://www.isotc211.org/2005/gco"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:gml="http://www.opengis.net/gml/3.2"
xmlns:gss="http://www.isotc211.org/2005/gss"
xmlns:gts="http://www.isotc211.org/2005/gts"
xmlns:gsr="http://www.isotc211.org/2005/gsr"
xmlns:ef="http://inspire.jrc.ec.europa.eu/schemas/ef/2.0"
xmlns:base2="http://inspire.jrc.ec.europa.eu/schemas/base2/0.1"
xmlns:om="http://www.opengis.net/om/2.0"
xmlns:swe="http://www.opengis.net/swe/2.0"
xmlns:sams="http://www.opengis.net/samplingSpatial/2.0"
xmlns:sam="http://www.opengis.net/sampling/2.0"
xmlns:am="http://inspire.jrc.ec.europa.eu/schemas/am/2.0"
xmlns:gn="urn:x-inspire:specification:gmlas:GeographicalNames:3.0"
xmlns:am-ru="http://inspire.jrc.ec.europa.eu/schemas/am-ru/2.0"
xsi:schemaLocation="http://www.exampleURI.com/AQD aqd/1.0/AQD.xsd http://www.opengis.net/gml/3.2 gml/3.2.1/gml.xsd"
gml:id="aqd.es.zones"
>
<!-- Responsible Party Information -->
<aqd:AQD_ReportingUnits>
<am-ru:reportingAuthority>
<gmd:CI_ResponsibleParty>
<gmd:organisationName>Subdirección General de Calidad del Aire y Medio Ambiente Industrial</gmd:organisationName>
</gmd:CI_ResponsibleParty>
</am-ru:reportingAuthority>
</aqd:AQD_ReportingUnits>
其中值'xsi:schemaLocation=http://www.exampleURI.com/AQD 出现“aqd/1.0/aqd.xsd”时,我只想将“aqd/1.0/aqd.xsd”更改为aqd.xsd
感谢您帮助您降低了操作速度,如果文件太大,您不需要minidom,请以其他方式操作:
outFile = open('path/to/outfile/out_file.xml', 'w')
inFile = open('path/to/input/input_file.xml', 'r')
for line in inFile:
if 'xsi:schemaLocation="http://www.exampleURI.com/AQD aqd/1.0/AQD.xsd' in line:
line = line.replace('aqd/1.0/AQD.xsd', 'AQD.xsd')
outFile.write(line)
inFile.close()
outFile.close()
谢谢,这个方法很管用,但理想情况下我会使用dom,因为有些文件是海量的。