I have a really poorly formatted XML file and I am looking to replace the names of some of the tags.
For example...
<column name="id">1</column>
should become
<id>1</id>
I have over 7000 entries and don't fancy doing this by hand. I am using Dreamweaver's Find & Replace. Obviously the value "1" in the example is a dynamic value.
Cheers for any help...
Find:
<column name="id">(\d+)</column>
Replace with
<id>$1</id>
Make sure you check Use regular expression in the dialog box.
搜索: <column name="id">(.*)</column>
替换为: <id>\\1</id>
A simple python solution, probably easier using Perl:
import re # regular expression
import sys # command line arguments
pat = re.compile(r'<column name=\"id\">(\d*)</column>', re.IGNORECASE)
if __name__=='__main__':
filename = sys.argv[1]
for line in open(filename):
matchObj = pat.search(line)
if matchObj != None:
s"<id>" + matchObj.group(1) + "</id>"
else:
print line
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.