0

I have the following 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="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>

And where the value ' xsi:schemaLocation="http://www.exampleURI.com/AQD aqd/1.0/AQD.xsd' occurs I simply want to change the 'aqd/1.0/AQD.xsd' to AQD.xsd

Thanks for helping

4

1 回答 1

0

这样做的方式很慢,您不需要 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()
于 2012-05-02T11:27:06.700 回答