Selvakumar has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
i have a file like this

<differentiation>
<differentiated-content differentiation="Emphasis3" xlink:type="simple">Dedication</differentiated-content>
</differentiation>
<differentiation>
<para differentiation="Emphasis3" xlink:type="simple">Dedication</para>
</differentiation>

now i want to find and replace the tags (whatever) within "differentiation". how can i do this?. Note this in my file not a single line. all are new line as mentioned

Replies are listed 'Best First'.
Re: Find and replace
by toolic (Bishop) on Jun 03, 2009 at 11:59 UTC
    i want to find and replace the tags (whatever) within "differentiation".
    Replace them with what? You should show your desired output.

    Since this looks like XML, I would start with XML::Twig.

Re: Find and replace
by bichonfrise74 (Vicar) on Jun 03, 2009 at 17:07 UTC
    If I understand your question properly, here is what I would do...
    #!/usr/bin/perl use strict; while (<DATA>) { if (/^\<differentiation\>/ ... /^\<\/differentiation\>/ ) { s/\<.*\>/new/g if ! ( /\<differentiation\>/ || /\<\/differenti +ation\>/ ); print; } } __DATA__ <differentiation> <differentiated-content differentiation="Emphasis3" xlink:type="simple +">Dedication</differentiated-content> </differentiation> <differentiation> <para differentiation="Emphasis3" xlink:type="simple">Dedication</para +> </differentiation>

      In other words i can say that i need to find some elements in a XML file and i need to process. For example within <para>...</para> or ... etc., to find and replace text, like that. Hope i made clear now.

Re: Find and replace
by Anonymous Monk on Jun 03, 2009 at 13:27 UTC
    This is a job for XSLT an XML-based language used for the transformation of XML documents into other XML or "human-readable" documents.
A reply falls below the community's threshold of quality. You may see it by logging in.