[bcn-pm] XML::Simple
Javier Arturo Rodriguez
codehead a gmail.com
div maig 17 07:18:27 PDT 2013
Hola Arnau,
Tu primer domain no tiene id -- según la documentación, XMLin tendría
que darte un warning:
> Note: "XMLin()" will generate a warning (or a fatal error in "STRICT
> MODE") if this syntax is used and an element which does not
> have the
> specified key attribute is encountered (eg: a ’package’ element
> without
> an ’id’ attribute, to use the example above). Warnings will
> only be
> generated if −w is in force.
Ponle el atributo id al tag faltante y funcionará como esperas.
Con un cordial saludo
-Javier Arturo Rodríguez
On 2013-05-17 15:16 , Arnau Bria wrote:
> Hola,
>
> estic intentant parsejar un fitxer xml usant XML::Simple .
> estic mirant l'exemple de:
> http://search.cpan.org/~grantm/XML-Simple-2.20/lib/XML/Simple.pm (jo tinc la 2.18, però no crec que canvii molt) i
> http://docstore.mik.ua/orelly/perl4/cook/ch22_02.htm#perlckbk2-CHP-22-SECT-1 .
>
>
> el xml :
>
> <?xml version="1.0" ?>
> <quota-report time="1368754202">
> <global-config>
> <quota-global-config>
> <reports>
> <schedule-pattern>1100000000|every sunday at 11pm</schedule-pattern>
> <schedule-dir>/ifs/.isilon/smartquotas/reports</schedule-dir>
> <schedule-copies>10</schedule-copies>
> <adhoc-dir>/ifs/.isilon/smartquotas/reports</adhoc-dir>
> <adhoc-copies>10</adhoc-copies>
> </reports>
> </quota-global-config>
> </global-config>
> <global-notify>
> </global-notify>
> <domains>
> <domain type="default-user" snaps="0" lin="0x00000001041778eb">
> <path>/ifs/users</path>
> <inactive/>
> <enforcements default-resource="logical">
> </enforcements>
> <notifications use="global"/>
> </domain>
> <domain type="user" snaps="0" lin="0x00000001041778eb" id="0">
> <id-name>root</id-name>
> <usage resource="physical">1188537212416</usage>
> <usage resource="logical">1011751744193</usage>
> <usage resource="inodes">761707</usage>
> <path>/ifs/users</path>
> <inactive/>
> <enforcements default-resource="logical">
> </enforcements>
> <notifications use="global"/>
> </domain>
> <domain type="user" snaps="0" lin="0x00000001041778eb" id="27">
> <inherited/>
> <id-name></id-name>
> <usage resource="physical">77689344</usage>
> <usage resource="logical">65421312</usage>
> <usage resource="inodes">19</usage>
> <path>/ifs/users</path>
> <inactive/>
> <enforcements default-resource="logical">
> </enforcements>
> <notifications use="default"/>
> </domain>
>
> [...]
> </domains>
> </quota-report>
>
>
> I m'interessa indeificat per id de cada domain. Doncs bé, intento
> dir-li que el camp clau (KeyAttr) és domain => id:
>
> my $data = $xml->XMLin("$log_path"."usage-"."$yymmdd".".log", ForceArray => 1, KeyAttr => {'domain' => 'id'});
>
> però passa de mi olímpicament. em mostr lo mateix si ho poso o si no ho
> poso:
> print Dumper $data;
>
> $VAR1 = {
> 'global-notify' => {},
> 'domains' => {
> 'domain' => [
> {
> 'notifications' => {
> 'use' => 'global'
> },
> 'enforcements' => {
> 'default-resource' => 'logical'
> },
> 'inactive' => {},
> 'path' => '/ifs/users',
> 'lin' => '0x00000001041778eb',
> 'type' => 'default-user',
> 'snaps' => '0'
> },
> {
> 'usage' => [
> {
> 'resource' => 'physical',
> 'content' => '1188537212416'
> },
> {
> 'resource' => 'logical',
> 'content' => '1011751744193'
> },
> {
> 'resource' => 'inodes',
> 'content' => '761707'
> }
> ],
> 'enforcements' => {
> 'default-resource' => 'logical'
> },
> 'inactive' => {},
> 'path' => '/ifs/users',
> 'lin' => '0x00000001041778eb',
> 'snaps' => '0',
> 'notifications' => {
> 'use' => 'global'
> },
> 'id-name' => 'root',
> 'type' => 'user',
> 'id' => '0'
> },
> {
> 'usage' => [
> {
> 'resource' => 'physical',
> 'content' => '77689344'
> },
> {
> 'resource' => 'logical',
> 'content' => '65421312'
> },
> {
> 'resource' => 'inodes',
> 'content' => '19'
> }
> ],
> 'enforcements' => {
> 'default-resource' => 'logical'
> },
> 'inactive' => {},
> 'path' => '/ifs/users',
> 'lin' => '0x00000001041778eb',
> 'snaps' => '0',
> 'inherited' => {},
> 'notifications' => {
> 'use' => 'default'
> },
> 'id-name' => {},
> 'type' => 'user',
> 'id' => '27'
> },
> {
> 'usage' => [
>
> [...]
>
>
> etc...
>
> algú m'explica on tinc l'error¿ millor utilitzar algun altre mòdul per
> parsejar ?
>
> com sempre, gràcies per endavant!
> Arnau
> _______________________________________________
> llista dels Barcelona-pm
> Barcelona-pm at pm.org
> http://mail.pm.org/mailman/listinfo/barcelona-pm
> BCN Perl Mongers: http://barcelona.pm.org
Més informació sobre la llista de correu Barcelona-pm