CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
substr() for repeats???

 



novicemonkey
Novice

Mar 26, 2004, 8:07 AM

Post #1 of 3 (183 views)
substr() for repeats??? Can't Post

I have an xml file which contains lots of <page>pagename1</page> tags, i wanted to extract the pagenames between these tags and store them in an array to produce:

@array = (pagename1, pagename2........).

at teh moment i know how to locate the string "<page>" using the index function then using this to extract the bit between the tags but only know how to do that for the first set of page tags it finds? How do i do it for multiple tags?



cheers j


davorg
Thaumaturge / Moderator

Mar 27, 2004, 6:06 AM

Post #2 of 3 (182 views)
Re: [novicemonkey] substr() for repeats??? [In reply to] Can't Post

The third argument to index gives the position in the string at which the search starts. You could use that to start the subsequent searches at the point at which the previous one ended.

But you _really_ don't want to be parsing XML files using string functions like that. You should look at a real XML parser. Sounds to me that XML::XPath would be very useful to you here.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


novicemonkey
Novice

Mar 29, 2004, 12:18 AM

Post #3 of 3 (176 views)
Re: [novicemonkey] substr() for repeats??? [In reply to] Can't Post

In which case is it possible to put the result of an xml/xslt translation in a perl variable? Basically the perl program i am coding should take the page names and combine all of those pages into one big xml file. I have done xml for quite a while now and its alot easier to combine up to 30 files using perl than it is using xslt. All i need to do at the mo is find some way of getting the 30 names in the array.

cheers

james

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives