Maxim has asked for the wisdom of the Perl Monks concerning the following question:
#!C:\PERL\bin\perl.exe use strict; use CGI ':standard'; use XML::Simple; #Variables my $var; my $var1; my $var2; $var = 'kool'; $var1 = 'max'; $var2 = "800.55.01"; print header; my @data = ('C:\Program Files\Apache Group\Apache2\htdocs\legastro +nome\XML\Admin\coffee.xml'); my $xml = XMLin((join'', @data)); foreach my $sub (@{$xml->{'subcategory'}}) { foreach my $product (@{$sub->{'product'}}) { foreach my $prod_id (@{$sub->{'prod_id'}}) { if ($prod_id eq $var2) { $prod_id = '800'; #Testing variables :) print "<html><head></head>"; print "<body>"; print "<p>Test</p>"; print "<p><h1>Done</h1></p>"; print "<br\>"; print "<br><br><a href=\'javascript:window.close();\'> +Close this window </a>"; print "</body></html>"; } else { #Testing variables :) print "<html><head></head>"; print "<body>"; print "<p>Test</p>"; print "<p><h1>Fail!!!</h1></p>"; print "<br\>"; print "<br><br><a href=\'javascript:window.close();\'> +Close this window </a>"; print "</body></html>"; } } } } ===DATA=== <?xml version="1.0" encoding="us-ascii"?> <?xml-stylesheet type="text/xsl" href="Adminproduct.xsl"?> <category name="Coffee"> <heading>150 years of know how at the service of a same strate +gy: Taste</heading> <photo>images/bag_legal.jpg</photo> <comments> <paragraph>Roaster since 1851, Café Legal has a perfect + knowledge of the green coffee market.</paragraph> <paragraph>A revolution in the packaging arena, Café Le +gal is at the origin of a major break through on the coffee market.</ +paragraph> </comments> <subcategory name="Prestige"> <comments><paragraph>Prestige is a very traditional French + recipe: a blend of Robusta and Arabica beans. The Robusta is known f +or its strength and the Arabica for its delicate flavour.</paragraph> </comments> <photo>images/prestige.jpg</photo> <product>Coffee <channel>D</channel> <channel>A</channel> <product_id>800.55.01</product_id> <brand>Legal</brand> <description>Legal Prestige</description> <conditionning unit="gr">250</conditionning> <packaging_qty>12</packaging_qty> <recipe>/recipes/coffee1.html</recipe> </product> </subcategory> </category>
20040928 Janitored by Corion: Put code in readmore tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help XML Search and replace
by borisz (Canon) on Sep 28, 2004 at 13:26 UTC | |
by Maxim (Sexton) on Sep 28, 2004 at 19:10 UTC | |
by Maxim (Sexton) on Sep 28, 2004 at 20:29 UTC | |
by borisz (Canon) on Sep 28, 2004 at 21:03 UTC | |
by Maxim (Sexton) on Sep 28, 2004 at 21:54 UTC | |
|
Re: Help XML Search and replace
by zejames (Hermit) on Sep 28, 2004 at 12:34 UTC | |
by Aristotle (Chancellor) on Sep 28, 2004 at 12:49 UTC |