Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unrecognised option: ForceArray ?

Status
Not open for further replies.

donny750

Programmer
Joined
Jul 13, 2006
Messages
145
Location
FR
hello;

I use the XML::Simple modul in my script and i have an errors
Unrecognised option: ForceArray at C:\Documents and Settings\donny\Bureau\a\parser.pl line 9

I can't use the modul options and i don't no why ?

Can you help me .?

Thanks
 
my xml
Code:
<?xml version="1.0" encoding="windows-1250"?>
<base>
<table nom="pilote"> 
 <champs intitule="numpilote" nom="john" prenom="jina"> 
</champs>   
 </table> 
<table nom="vol"> 
 <champs intitule="xx32" ville="paris"> 
   
  </champs>
 </table> 
</base>

[code]

my perl script 

[code]
#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;
$xml = new XML::Simple() ;
$data = $xml->XMLin("./fili.xml",ForceArray => 1);
print  Dumper($data); 
[code]
 
Try:
Code:
#!/usr/bin/perl
use XML::Simple;
use Data::Dumper;
$xml = new XML::Simple([COLOR=blue]ForceArray => 1[/color]) ;
$data = $xml->XMLin("./fili.xml");
print  Dumper($data);

-------------
Kirsle.net | Kirsle's Programs and Projects
 
yes it's run
but i've the same result with ForceArray or not.
with
Code:
$xml = new XML::Simple(ForceArray => 1) ;
     $data = $xml->XMLin("./fili.xml");
$VAR1 = {
'table' => [
{
'nom' => 'pilote',
'champs' => {
'prenom' => 'jina',
'nom' => 'john',
'intitule' => 'numpilote'
}
},
{
'nom' => 'vol',
'champs' => {
'intitule' => 'xx32',
'ville' => 'paris'
}
}
]
};

with
Code:
$xml = new XML::Simple() ;
$data = $xml->XMLin("./fili.xml");

$VAR1 = {
'table' => [
{
'nom' => 'pilote',
'champs' => {
'prenom' => 'jina',
'nom' => 'john',
'intitule' => 'numpilote'
}
},
{
'nom' => 'vol',
'champs' => {
'intitule' => 'xx32',
'ville' => 'paris'
}
}
]
};


but i think it's not good because i've try this examples
forcearray => 1 (in)

This option should be set to '1' to force nested elements to be represented as arrays even when there is only one. Eg, with forcearray enabled, this XML:
<opt>
<name>value</name>
</opt>
would parse to this:

{
'name' => [
'value'
]
}
instead of this (the default):

{
'name' => 'value'
}

from this web site http://perlhelp.web.cern.ch/perlhelp/ and i've not the same result;
i've always
$VAR1 = {
'name' => 'value'
};
 
perldoc XML::Simple said:
ForceArray => 1 *# in - important*
This option should be set to '1' to force nested elements to be represented as arrays even when there is only one.
As it says in the docs, ForceArray effects nested elements, it doesn't appear to have the same behaviour on attributes within the elements.

There are lots of XML parsers on CPAN, you might be able to find one that does what you want. Alternately, at least with your example, the XML file doesn't appear to be very complicated - you can probably put something together with XML::Parser that will do what you want.

What are you expecting the final data structure to look like?
 
Maybe you can use the other ForceArray option:

ForceArray => [ names ] # in - important

This alternative (and preferred) form of the 'ForceArray' option allows you to specify a list of element names which should always be forced into an array representation, rather than the 'all or nothing' approach above.

- Kevin, perl coder unexceptional!
 
I have a feeling that the problem is going to be the same - it's meant for elements not attributes of the elements. But it can't hurt to try! [ponder]
 
you'e probably right [sadeyes]

- Kevin, perl coder unexceptional!
 
thanks
with xml parser
I want to parse a xml file , in this file ,find a value of an attribute
(for example <customer age="32">) modify the value (<customer age="33">);
Can I do it with XML::Parser ??
 
Is there something I'm missing? Why do you need 'ForceArray'? From the sounds of things, XML simple should do what you want.
 
Forcearray makes it easier to deal with the results. If you have an element that sometimes has one and other times has multiple occurrences, the switching between arrays and not makes your code more complicated.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::PerlDesignPatterns)[/small]
 
with XML::Simple i can modify the value of an attribute in an xml file you say.
rharsh say
Is there something I'm missing? Why do you need 'ForceArray'?
The problem isn't focalized on forcearray but if i can't use forcearray, i can't use the others options of the XML::Simple parckage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top