Discussion on:

16
Comments

Join the conversation!

Follow via:
RSS
Email Alert
I have tried every way I could possibly think of trying to get the ForceArray parameter to work, without success. I have even done a cut/past into DzSoft Perl Editor with the examples in this article without the results displayed in this article. What else do I need? - Frank
very good article, did come accross one problem tho and found that Frank also came across it but probably woulda figured it out by now.
but for anyone else heres what i found:
The options passed are case sensitive. ForceArry => 1 doesn't work (for me anyway) took me a while but finally figured it out and changed it to forcearray => 1
Nice post, really helped me happy, great piece of effort.

//Jaduks, India
This article has been a lot of help. I have a problem though,when writing perl structures to XML, is there a way I can prevent those tags from appearing ?
U KICK ASS, OTHER PAGES JUST CONFUSED ME, YOU REALLY HELPED, THANKS A TON MAN!!!!!!!!!!!!!!!!!!!!!!!!!
#!/usr/bin/perl -w

=comment
by joel almeida garcia
aullidolunar (at-nis-@) (g-m-a-i-l) (dot-.) (c-0-m)
=cut

use strict;
use XML::Simple;
use Data::Dumper;

my $xml = XML::Simple->new(RootName => "xml"); #main node
print "What's your name: ";
my $nombre = ; # input some name
chomp $nombre;
print "What's your age: ";
my $edad = ; # some age
chomp $edad;
print "What's the name of your girl or boyfriend: ";
my $chica = 1); # use our array data, use process information
print Dumper($data), "\n"; # print the xml into the terminal
exit(0);
So far, this is the clearest example of Perl code to read and interpret XML I've found on the web yet, in two days of searching!

However, there is no explanation of how to read element attributes. For example:

How do I get Id?
EXCELLENT simple explanation & sample - thx.
0 Votes
+ -
Does anyone know how can be search for specific xml tag using Perl?

Thanks,
Bhawk2
0 Votes
+ -
appreciation
subhadeep2007 27th Apr 2011
truly man...very helpful...keep up the good work happy
Hi,

Nice article, But Listing C code for Listing A xml only works if there are multiple employee elements in xml. For only a single {department}, "\n";
print "\n";
}
data.xml
----------------




JohnDoe
43
M
Operations


0 Votes
+ -
array problems
ambatiarunkumar Updated - 20th Jun
use particular tag in forcearray

$data = XMLin(("data.xml"),forcearray => ['employee']);
No. The solution you gave didnt work. Still throwing same error:
use XML::Simple;
use Data::Dumper;
$xml = new XML::Simple (KeyAttr=>[]);
#$data = $xml->XMLin("data.xml");
$data = XMLin(("data.xml"),forcearray => ['employee']);
foreach $e (@{$data->{employee}})
{
print $e->{name}, "\n";
print "Age/Sex: ", $e->{age}, "/", $e->{sex}, "\n";
print "Department: ", $e->{department}, "\n";
print "\n";
}
Not an ARRAY reference at test2.pl line 6.

data.xml Just 1 employee record.
-------------



JohnDoe
43
M
Operations



Can anyone please suggest some solution or alternative xml parser for nested xml structres, with one or many records.
If i have an XML document with a list of files, how do i create a perl script to read the XML to then copy the files listed into a directory?
0 Votes
+ -
$data->{employee}->[0]->{name} this is giving the value at specific path..
Same way i need to get the child node's names inside specific path (i.e., tag names inside {employee}->[0]->{name} ) i specify..
how to do this..

xml can be like,

xml
--employee
------name
---------fname /fname
---------lname /lname
------/name
--/employee
--employee
------name
---------fname /fname
---------lname /lname
------/name
--/employee
/xml


So, i want the tag names inside employee[0]->name (i.e., it should return me fname, lname)

Please share your suggestions.
Keyboard Shortcuts:
Prev
Next
Toggle
Join the conversation
Formatting +
BB Codes - Note: HTML is not supported in forums
  • [b] Bold [/b]
  • [i] Italic [/i]
  • [u] Underline [/u]
  • [s] Strikethrough [/s]
  • [q] "Quote" [/q]
  • [ol][*] 1. Ordered List [/ol]
  • [ul][*] · Unordered List [/ul]
  • [pre] Preformat [/pre]
  • [quote] "Blockquote" [/quote]

Join the TechRepublic Community and join the conversation! Signing-up is free and quick, Do it now, we want to hear your opinion.