It looks like what u want to do is attribute folding.  That's when u take a
nested XML tag and make it an attribute of an enclosing tag.  Ur doing
something slightly different which is merging equal depth tags.  The right
way to do this is with an XML parser.  Look into XML::Simple to get started.
U would read in the XML to a hash, manipulate the data in the hash, and then
write out a new XML file.

Regex can do this in a degenerate case but it becomes unmanageable fast.
But since u asked....

$xml =~
s{<index-item>(\s*)<index-entry>([^<]*)</index-entry>\s*<pageId>([^<]*)</pag
eId>(\s*)</index-item>}{<index-item>$1<index-entry
pages="$3">$2</index-entry>$4</index-item>}sg;

HTH


At 09:25 PM 2/26/2010 +0530, Kprasad wrote:
>Hi All
>
>What will be the perfect Regular Expression to convert below mentioned
'Search Text' to 'Replacement Text' while 'Single Line' option is ON.
>
>When I use below mentioned Regex
><index-entry(?:[^>]+)?>((?!<\/index-entry>).*?)</index-entry>\s*<pageId>([0
-9]+)</pageId>
>
>And replaces wrongly
>
><index-entry pages="32">arousal disorders</index-entry><see
href="c-86679-1" label="see">disorders of arousal</see>
></index-item>
>.....................
>
>Search Text:
>
><index-item>
><index-entry>APOE e4 variant</index-entry> <pageId>18</pageId>
></index-item>
><index-item>
><index-entry>arousal disorders</index-entry> <see href="c-86679-1"
label="see">disorders of arousal</see>
></index-item>
><index-item>
><index-entry>arterial blood gas tests</index-entry> <pageId>32</pageId>
></index-item>
><index-item>
><index-entry>asthma</index-entry> <pageId>28--9, 295</pageId>
></index-item>
>
>Correct Replacement Text should be:
>
><index-item>
><index-entry pages="18">APOE e4 variant</index-entry>
></index-item>
><index-item>
><index-entry>arousal disorders</index-entry> <see href="c-86679-1"
label="see">disorders of arousal</see>
></index-item>
><index-item>
><index-entry pages="32">arterial blood gas tests</index-entry>
></index-item>
><index-item>
><index-entry pages="28--29,295">asthma</index-entry>
></index-item>
>


--
REMEMBER THE WORLD TRADE CENTER         ---=< WTC 911 >=--
"...ne cede malis"

00000100

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to