Hi I have some problems when I use the XML search and replace. I have try everything to do it but I can't. I am using xml::simple to replace a value from an XML file.
Here my code
#!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&#xE9; Legal has a perfect + knowledge of the green coffee market.</paragraph> <paragraph>A revolution in the packaging arena, Caf&#xE9; 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>

----------------------------------------------
I always got the error message "Not an ARRAY reference at C:\Program Files\Apache Group\Apache2\cgi-bin\legas\in .pl line 37." Thanks in advance Maxim

20040928 Janitored by Corion: Put code in readmore tags


In reply to Help XML Search and replace by Maxim

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.