----- Original Message -----
From: Patrick James
Subject: Re: Searching and Replace XML


> On Jul 27, 2007 Daniel Farnworth wrote:
> 
> > Hi,
> > 
> > I have an XML document within which I need to comment out various
> > '<dict>...</dict>' sections.
> > 
> > Can anybody suggest a search pattern I can use to find this type of
> pattern
> > and replace with <!--<dict>...</dict>-->
> 
> Hi Daniel
> 
> I'm going to have a go.
> 
> Find:
> 
> <dict>(?s).+?</dict>
> 
> Replace:
> 
> <!--&-->
> 
> Here's an attempt at an explanation
> 
> <dict>
> 
> Finds the first incidence of that
> 
> .
> 
> Finds any character that isn't a return
> 
> .+
> 
> Finds one or more of that character, however that will include the
> characters 
> in </dict> and after and we want the search pattern to end there so we put
> 
> ?
> 
> after .+ to tell it to only to search until the next defined characters in 
> the search expression are found.
> 
> It might well be that there are return characters between <dict> and </dict>
> 
> in the file so we put a switch to tell
> 
> .
> 
> to find return characters, turning it into something that will find
> anything.
> The switch is like this:
> 
> (?s)
> 
> So, in the middle we have:
> 
> (?s).+?
> 
> after it we put </dict> to say that where the searched selection is going to
> 
> end.
> 
> Now for the replace that is simple because we can "match all of the search 
> expression" using:
> 
> &
> 
> as you want the <!-- and --> before and after then the replace expression
> is:
> <!--&-->
> 
> There is one caveat which is that if you have <dict> nested it will go
> wrong.
> <dict>some stuff<dict>some stuff</dict>some stuff</dict>
> 
> will become
> 
> <!--<dict>some stuff<dict>some stuff</dict>-->some stuff</dict>
> 
> so as long as there are no nested <dict> then it will, I hope be okay.
> 
> 
> -- 
> Patrick

Nicely done Patrick, I haven't had a chance to check yet but it looks good.

I'll comment back later once I have had a chance to test...

Dan


The information contained in this communication is intended solely for the use 
of the individual or entity to whom it is addressed and others authorised to 
receive it. It may contain confidential or legally privileged information. If 
you are not the intended recipient you are hereby notified that any disclosure, 
copying, distribution or taking any action in reliance on the contents of this 
information is strictly prohibited and may be unlawful. If you have received 
this communication in error, please notify [EMAIL PROTECTED] immediately and 
then delete this email from your system. Any views or opinions presented in 
this email are solely those of the author and do not necessarily represent 
those of The Creative Partnership. The Creative Partnership has taken every 
reasonable precaution to ensure that any attachment to this e-mail has been 
swept for viruses. However, The Creative Partnership cannot accept liability 
for any damage sustained as a result of software viruses and would advise that 
you carry out your own virus checks before opening any attachment.


--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to