in reply to Re: Write XML file
in thread Write XML file

Well I try guys. It still the same as before. I will something else. Than XML::simple.

Replies are listed 'Best First'.
Re^3: Write XML file
by ikegami (Patriarch) on Sep 30, 2004 at 04:46 UTC

    Here's a working exaple:

    use XML::Simple; my $data = <<'__EOI__'; <?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</paragraph> <paragraph>A revolution in the packaging arena</paragraph> </comments> <subcategory name="Prestige"> <comments><paragraph>Prestige is a very traditional French + recipe</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> <product>Coffee <channel>D</channel> <channel>A</channel> <product_id>801.55.01</product_id> <brand>Legal</brand> <description>Legal Prestige Boite Ar&#xF4;me</descript +ion> <conditionning unit="gr">500</conditionning> <packaging_qty>6</packaging_qty> </product> </subcategory> </category> __EOI__ # In older versions: $category = XMLin($data, forcearray=>1); XMLout($category, rootname =>'category', outputfile => \*STDOUT); # In newer versions: #$category = XMLin($data, ForceArray=>1); #XMLout($category, RootName =>'category', OutputFile => \*STDOUT); __END__ output ====== <category name="Coffee"> <subcategory name="Prestige"> <photo>images/prestige.jpg</photo> <product>Coffee <packaging_qty>12</packaging_qty> <product_id>800.55.01</product_id> <conditionning unit="gr">250</conditionning> <brand>Legal</brand> <channel>D</channel> <channel>A</channel> <recipe>/recipes/coffee1.html</recipe> <description>Legal Prestige</description> </product> <product>Coffee <packaging_qty>6</packaging_qty> <product_id>801.55.01</product_id> <conditionning unit="gr">500</conditionning> <brand>Legal</brand> <channel>D</channel> <channel>A</channel> <description>Legal Prestige Boite Ar¶me</description> </product> <comments> <paragraph>Prestige is a very traditional French recipe</paragra +ph> </comments> </subcategory> <photo>images/bag_legal.jpg</photo> <heading>150 years of know how at the service of a same strategy: Ta +ste</heading> <comments> <paragraph>Roaster since 1851</paragraph> <paragraph>A revolution in the packaging arena</paragraph> </comments> </category>
      Thank you very much for your help. I found another way which I use this"
      #!C:\PERL\bin\perl.exe use strict; use CGI ':standard'; use XML::Simple; #Variables my $arrays = [qw/subcategory packaging_qty recipe description prod +uct paragraph comments channel brand conditionning product_id heading + photo/]; my $cat = 'C:\Program Files\Apache Group\Apache2\htdocs\legastrono +me\XML\Admin\test4.xml'; my $category = XMLin( (join'', $cat), KeyAttr => 1, 'ForceArray' = +> $arrays); XMLout($category, rootname =>'category', outputfil +e =>('C:\Program Files\Apache Group\Apache2\htdocs\legastronome\XML\A +dmin\test4.xml'));
      I can say it works well. I found your way better because there is less code. But I need now to put the first two lines at the begin. I am still trying. Again thanks. Really this website is the best.