Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Perl Index Replace

by Rajasekaran (Initiate)
on Sep 23, 2014 at 15:26 UTC ( [id://1101666]=perlquestion: print w/replies, xml ) Need Help??

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

I am working with book.xml. I have added lot of Link for page Name with page numbers in Index Part

<secondaryie><link xml:id="ind2" linkend="ind2a">Apricot, Plum, and Ra +spberry</link>140,141</secondaryie>
. I want to find the page name
Apricot, Plum, and Raspberry
and page number
[<author id="page4" />]
in file except index tags and find the pageno (
<author id="page140" />
) and page Name in top of the file and replace the link in the page name
<link xml:id="ind1a" linkend="ind1">Apricot, Plum, and Raspberry<\/lin +k>
. I have tried lot of methods, but i didnt get the solution. Please Suggest.

Replies are listed 'Best First'.
Re: Perl Index Replace
by Anonymous Monk on Sep 23, 2014 at 15:33 UTC

      If you are walking through the XML without an XML package module, you might want to consider the use of PERL's flip-flop operator, to position your read within the block of the XML you are wanting to process.

        I would hesitate to recommend the flip-flop operator to a Perl newcomer. In fact, I would hesitate several times to recommend it to anyone. If someone is advanced enough to use it, they perhaps have already found it, and can deal with the inherent surprises.

        Without code, and without an XML walker of some type, we are just guessing according to our favored solutions. Best to see the engine before the mechanic makes a diagnosis.

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of

Re: Perl Index Replace
by Anonymous Monk on Sep 25, 2014 at 12:15 UTC

    Thank you for providing more information. Unfortunately it's still a bit unclear to me, for example where do you get the "page4" from, and how does "ind2a" get changed to "ind1"? A few more lines of input might help, or even better, if you could reduce the input down to a small (say 5-20 lines) example that preserves the structure of the input XML, it would help greatly.

    At the moment, I can only give the general advice of looking into one of the XML parsing modules, such as XML::LibXML, especially the findnodes function (see XML::LibXML::Node), or perhaps XML::Twig.

    (In the future, please indicate in your posting when you update/change it, see How do I change/delete my post?)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1101666]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 19:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found