Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: XML::Twig question

by anniyan (Monk)
on Nov 24, 2005 at 11:11 UTC ( #511405=note: print w/ replies, xml ) Need Help??


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

mirod If you go through my yesterday's posting you can able to know my requirement. I want to avoid giving full path, i just want to give only the starting tags and ending tags with any depth inbetween. How to do that? Also as per my ini file i am getting the input with '<' symbol, but i will replace that before passing it to twig handler.

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


Comment on Re^2: XML::Twig question
Re^3: XML::Twig question
by mirod (Canon) on Nov 24, 2005 at 17:35 UTC

    Honestly, I can't think of too many cases where being able to specify the top and lowest level tags only would make much sense. So maybe a more realistic example, or a quick explanation of why you need to do this, would probably get a more relevant answer.

    Anyway, in general, when you get to the limit of the mini-language used to declare handlers, the solution is to "finish the job" in the handler itself. So filter first the regular way, and test the rest of the condition at the begining of the handler, returning if it is not met.

    So you would have for example:

    my $twig= XML::Twig->new( twig_handlers => { title => \&title }) ->parsefile( "foo.xml"); sub title { my( $twig, $title)= @_; # return 1 (true) if you can have other handlers on the # title, otherwise it doesn't matter what you return # see the doc for twig_handlers return 1 unless( $title->root->matches( 'gutbook'); $title->set_tag( 'tit'); }

    Does it help?

      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)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://511405]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2014-09-19 04:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls