http://www.perlmonks.org?node_id=511634


in reply to Re^3: XML::Twig question
in thread XML::Twig question

mirod thanks for your patience and assistance. I will explain fully the job i am doing now.

I am having an ini file in which they give conditions like shown below.

########## condition ############## <condition> <chap/<ch/<sec/<p/<anchor==<anchors </condition> ########## andcondition ############## <andcondition> <book&&<chap/<ch/<sec/<p/<para==<paragraph </andcondition> ########## orcondition ############## <orcondition> <book||<chap/<ch/<sec/<p/<ca==<caption </orcondition> ########## noncondition ############## <noncondition> <para/<author==<auth </noncondition> ########## andnoncondition ############## <andnoncondition> <book&&<chap//<anchor/<para/<it==<italics </andnoncondition> ########## ornoncondition ############## <ornoncondition> <book||<chap//<anchor/<para/<b==<bold </ornoncondition>

Now i will explain what the ini file is to do.


1. <condition>: we have to fetch that path and search in the xml file and replace 'anchor' with 'anchors' which is given after == sign.
2. <andcondition>: In and condition 'para' element should be checked in both parent 'book' and 'chap' and if it is present in both then replace 'para' with 'paragraph' which is given after == sign
3. <orcondition>: In or condition 'ca' element should be checked in both parent 'book' and 'chap' and if it is present either in one or both then replace 'para' with 'caption' which is given after == sign
4. <noncondition>: In non condition we have to fetch that path and search in the xml file and don't replace 'author' with 'auth' in that location and replace it in other locations which is given after == sign.
5. <andnoncondition>: In and non condition 'it' element should be checked in both parent 'book' and 'chap' and if it is present in both then replace 'para' with 'paragraph' in all locations except in the given path.
6. <ornoncondition>: In or non condition 'b' element should be checked in both parent 'book' and 'chap' and if it is present either in one or both then replace 'b' with 'bold' in all locations except in the given path.

I will give just a sample xml file for the above conditions. Also the tool should do from 6 to 1 ie in reverse order, <ornonconition> to <condition>.

This is my requuirement and i am doing as shown in my original node. How to do this. There will be more than one entries in each condition.

input xml

<chap> <ch> <sec> <p> <anchor><b>THE ILIAD</b></anchor> <para> <author>HOMER</author> </para> <ca>check</ca> </p> </sec> <sec> <author><it>HOMER</it></author> <p> <anchor>BOOK I</anchor> <para> Sing, O goddess, <it>the anger </it>of Achilles son of Peleu +s, that brought countless ills upon the Achaeans. </para> </p> </sec> </ch> </chap>

I apologise for such long post.

Regards,
Anniyan
(CREATED in HELL by DEVIL to s|EVILS|GOODS|g in WORLD)