Home > Archive > PERL Beginners > July 2006 > RE: XML: :Simple -- can't print still: config problem?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
RE: XML: :Simple -- can't print still: config problem?
|
|
| Brian Bwarn 2006-07-25, 6:57 pm |
| Thank you both for your replies. I'm still not having
success with either Venkat's or Mumia's version of the
foreach loop. I tried an example of something that
should work--namely Listing C using the source in
Listing A of the how-to article at
http://builder.com.com/5100-6371-5363190.html.
I can't get anything to output with that either.
Is there something I should look for in my
configuration / module setup (I'm running perl v.5.6.1
(ActiveState Build 638) using the latest versions of
XML-Simple and Data-Dumper provided at
http://ppm.activestate.com/PPMPacka...x-builds-only/.
Thanks again,
BW
--- Venkat Saranathan <venkat_saranathan@gulfsoft.com>
wrote:
> The data structure is little more complicated than
> list of hashes due to the
> attributes in XML.
>
>
> Here is an updated version of your perl code.
>
> #use modules
> use XML::Simple;
> use Data::Dumper;
>
> # create object
> $xml = new XML::Simple (KeyAttr=>[]);
>
> # read XML file
>
> $data=
> $xml->XMLin("C:\\temp\\input.xml");
>
> # dereference hash reference
> # access <dataschemas> array
>
> print "before loop ...\n";
> foreach $d
> (@{$data->{dataschema}->{includes}->{include}}) {
> print "in \$d loop ...\n";
> print $d->{name}, "\n";
>
> }
> print "finished\n";
>
>
>
> with warm regards,
> Venkat Saranathan
> Gulf Breeze Software
> www.gulfsoft.com
>
> GulfBreeze Blog
> www.gulfsoft.com/blog
>
>
> -----Original Message-----
> From: brian bwarn [mailto:bwbperl@yahoo.com]
> Sent: Monday, July 24, 2006 6:00 PM
> To: beginners@perl.org
> Subject: XML::Simple -- can't get anything to print
> from array
>
>
> I'm just starting out with XML::Simple and can't get
> any output to display to STDOUT. What am I missing?
>
> -------------------
> Source XML snippet:
> -------------------
> <dataschemas>
> <dataschema name="defaultDB">
> <includes>
> <include name="Base Metadata"/>
> <include name="Extracted Re-Map"/>
> </includes>
> <attributes>
> <attribute category="" parser="TextParser"
> extract="true" segmentation="soft"/>
> </attributes>
> </dataschema>
> </dataschemas>
>
> ---------------
> Perl code:
> ----------------
> # use modules
> use XML::Simple;
> use Data::Dumper;
>
> # create object
> $xml = new XML::Simple (KeyAttr=>[]);
>
> # read XML file
>
> $data=
> $xml->XMLin("C:\datafiles\specialIncludes.xml");
>
> # dereference hash reference
> # access <dataschemas> array
>
> print "before loop ...\n";
> foreach $d (@{$data->{dataschema}}) {
> print "in \$d loop ...\n";
> print "dataschema is: ", $d->{includes}->{name},
> "\n";
> }
> print "finished\n";
>
> ---------------
> Output:
> ---------------
> before loop ...
> finished
>
> Thanks, BW
>
> ________________________________________
__________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam
> protection around
> http://mail.yahoo.com
>
> --
> To unsubscribe, e-mail:
> beginners-unsubscribe@perl.org
> For additional commands, e-mail:
> beginners-help@perl.org
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
>
>
>
>
>
> --
> To unsubscribe, e-mail:
> beginners-unsubscribe@perl.org
> For additional commands, e-mail:
> beginners-help@perl.org
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
>
>
>
________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
| |
| Mumia W. 2006-07-25, 6:57 pm |
| On 07/25/2006 10:49 AM, brian bwarn wrote:
> Thank you both for your replies. I'm still not having
> success with either Venkat's or Mumia's version of the
> foreach loop. [...]
Did you enable ForceArray?
Did you use Data::Dumper to look at the structure of what
XML::Simple returned?
| |
| Venkat Saranathan 2006-07-25, 6:57 pm |
| Could be. Because, the code that I sent works fine in my environment.=20
C:\temp>perl -v
This is perl, v5.8.7 built for MSWin32-x86-multi-thread
(with 14 registered patches, see perl -V for more detail)
Copyright 1987-2005, Larry Wall
Binary build 815 [211909] provided by ActiveState =
http://www.ActiveState.com
ActiveState is a division of Sophos.
Built Nov 2 2005 08:44:52
Perl may be copied only under the terms of either the Artistic License =
or
the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to =
the
Internet, point your browser at http://www.perl.org/, the Perl Home =
Page.
C:\temp>perl xml.pl
before loop ...
in $d loop ...
Base Metadata
in $d loop ...
Extracted Re-Map
finished
C:\temp>
with warm regards,
Venkat Saranathan
Gulf Breeze Software
www.gulfsoft.com
=20
GulfBreeze Blog
www.gulfsoft.com/blog
-----Original Message-----
From: brian bwarn [mailto:bwbperl@yahoo.com]=20
Sent: Tuesday, July 25, 2006 11:50 AM
To: beginners@perl.org
Subject: RE: XML: :Simple -- can't print still: config problem?
Thank you both for your replies. I'm still not having
success with either Venkat's or Mumia's version of the
foreach loop. I tried an example of something that
should work--namely Listing C using the source in
Listing A of the how-to article at
http://builder.com.com/5100-6371-5363190.html.
I can't get anything to output with that either.
Is there something I should look for in my
configuration / module setup (I'm running perl v.5.6.1
(ActiveState Build 638) using the latest versions of
XML-Simple and Data-Dumper provided at
http://ppm.activestate.com/PPMPacka...x-builds-only/.
Thanks again,
BW
--- Venkat Saranathan <venkat_saranathan@gulfsoft.com>
wrote:
> The data structure is little more complicated than
> list of hashes due to the
> attributes in XML.
>=20
>=20
> Here is an updated version of your perl code.
>=20
> #use modules
> use XML::Simple;
> use Data::Dumper;
>=20
> # create object
> $xml =3D new XML::Simple (KeyAttr=3D>[]);
>=20
> # read XML file
>=20
> $data=3D
> $xml->XMLin("C:\\temp\\input.xml");
>=20
> # dereference hash reference
> # access <dataschemas> array
>=20
> print "before loop ...\n";
> foreach $d
> (@{$data->{dataschema}->{includes}->{include}}) {
> print "in \$d loop ...\n";
> print $d->{name}, "\n";
>=20
> }
> print "finished\n";
>=20
>=20
>=20
> with warm regards,
> Venkat Saranathan
> Gulf Breeze Software
> www.gulfsoft.com
> =20
> GulfBreeze Blog
> www.gulfsoft.com/blog
>=20
>=20
> -----Original Message-----
> From: brian bwarn [mailto:bwbperl@yahoo.com]=20
> Sent: Monday, July 24, 2006 6:00 PM
> To: beginners@perl.org
> Subject: XML::Simple -- can't get anything to print
> from array
>=20
>=20
> I'm just starting out with XML::Simple and can't get
> any output to display to STDOUT. What am I missing?
>=20
> -------------------
> Source XML snippet:
> -------------------
> <dataschemas>
> <dataschema name=3D"defaultDB">
> <includes>
> <include name=3D"Base Metadata"/>
> <include name=3D"Extracted Re-Map"/>
> </includes>
> <attributes>
> <attribute category=3D"" parser=3D"TextParser"
> extract=3D"true" segmentation=3D"soft"/>
> </attributes>
> </dataschema>
> </dataschemas>
>=20
> ---------------
> Perl code:
> ----------------
> # use modules
> use XML::Simple;
> use Data::Dumper;
>=20
> # create object
> $xml =3D new XML::Simple (KeyAttr=3D>[]);
>=20
> # read XML file
>=20
> $data=3D
> $xml->XMLin("C:\datafiles\specialIncludes.xml");
>=20
> # dereference hash reference
> # access <dataschemas> array
>=20
> print "before loop ...\n";
> foreach $d (@{$data->{dataschema}}) {
> print "in \$d loop ...\n";
> print "dataschema is: ", $d->{includes}->{name},
> "\n";=20
> }
> print "finished\n";
>=20
> ---------------
> Output:
> ---------------
> before loop ...
> finished
>=20
> Thanks, BW
>=20
> ________________________________________
__________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam
> protection around=20
> http://mail.yahoo.com=20
>=20
> --=20
> To unsubscribe, e-mail:
> beginners-unsubscribe@perl.org
> For additional commands, e-mail:
> beginners-help@perl.org
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
>=20
>=20
>=20
>=20
>=20
> --=20
> To unsubscribe, e-mail:
> beginners-unsubscribe@perl.org
> For additional commands, e-mail:
> beginners-help@perl.org
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
>=20
>=20
>=20
________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around=20
http://mail.yahoo.com=20
| |
| DJ Stunks 2006-07-25, 6:57 pm |
| Venkat Saranathan wrote:
> Could be. Because, the code that I sent works fine in my environment.
what could be?? please don't top post.
-jp
|
|
|
|
|