Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTML Search and Replace Help

Status
Not open for further replies.

tmerola

MIS
Jan 8, 2003
2
US
Hello All -
I'm wondering if anyone has or knows of a search and replace script that can go through a directory of html files, search, extract a text string between 2 tags, compare the string against a table in another file, locate the corresponding object ID that matches the text string and then copy
that object ID back to the original html file.

For example, an editorial team has a ton of html files created in Dreamweaver with tables that link to other files. Their content management system generates object ID's for each file but the editors did not code the links and want an automated way to insert the object ID for links. There are thousands of files and even more links so a simple search and replace would take forever and they want something they can reuse in the future. Here's a snippet of the html code looks like this:

<table class="inouttable">
<tr>
<td><!-- InstanceBeginEditable name="EditRegion5" -->
<p><a href="AID=20OID=10000"><img>Application Test Plan</a></p>
<!-- InstanceEndEditable --></td>
<td><!-- InstanceBeginEditable name="EditRegion6" -->
<p><a href="AID=20OID=10000"><img>Test Scripts</a> </p>
<p><a href="AID=20OID=10000"><img>Test Data</a> </p>
<!-- InstanceEndEditable --></td>
</tr>
</table>
<!-- InstanceBeginEditable name="EditRegion7" -->

And what they need is a function that will go through html files, search between the EditRegion5 and EditRegion7 fields and extract the text strings between the <img> and </a> tags in the href. So in the snippet above the first match would be what's in the blue text below:
<p><a href="AID=20OID=10000"><img>Application Test Plan></a></p>

Next step needed would be to take that value (Application Test Plan), compare it against a look-up file which has a list of all the possible matches with object identifiers (OID) in parens.
Like this: Application Test Plan (10388)

So once the search finds a match in the look-up file, it would take OID in parens (10388) and copy it back to the original file and replace of OID value place holder. So
<p><a href="AID=20OID=10000"><img>Application Test Plan</a></p>

would become

<p><a href="AID=20OID=10388"><img>Application Test Plan</a></p>


Then repeat the process for each match before the EditRegion7 field in each file of a directory.

It sounded so simple at first thought it could be done with a standard search and replace tool but to my dismay needs a little more attention.

If anything has or knows of a script, tool, or anything else that can I can look at or modify to do any of the above steps it would be most appreciated!

Thanks in advance for any information.
 
And what have you tried so far ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top