0

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...

1
  • If you have some knowledge of XSLT, it could be done with a stylesheet (I dare not say "simple", I have never managed to write one in less than 30 minutes...) Commented Jan 4, 2012 at 15:00

3 Answers 3

2

Find:

<column name="id">(\d+)</column>

Replace with

<id>$1</id>

Make sure you check Use regular expression in the dialog box.

See further on Adobe's site.

Sign up to request clarification or add additional context in comments.

4 Comments

More likely, the OP was looking for <column name="([^"]+)">(\d+)</column> to be replaced by <$1>$2</$1>, but the direction looks correct.
You are both correct. Thanks for the accurate and speedy reply guys.
Yep, generalizing with the above solution looks like the way to go
Taking it one step further, I suppose <column name="([^"]+)">([^<])</column> replaced with <$1>$2</$1> is the way to go.
0

Search for: <column name="id">(.*)</column> Replace with: <id>\1</id>

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.