我有一个 XML,我想打印他的所有节点,我想访问电影节点字段。
我可以访问名称和城市,但我无法访问电影字段。
<OnlineCinema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Cinema.xsd">
<Cinema>
<City>Cluj</City>
<Name>Cinema2</Name>
<MovieName>ScaryMovie</MovieName>
<Movie>
<Name>ScaryMovie</Name>
<Genre>comedie</Genre>
<Director>lala</Director>
<Writer>asdf</Writer>
<Cast>asdvvb</Cast>
<Year>2010</Year>
<Trailer>http://www.youtube.com/embed/RMDZ8M47j0I</Trailer>
<NRLoc>400</NRLoc>
</Movie>
</Cinema>
代码:
use XML::Simple;
use Data::Dumper;
$xml = new XML::Simple (KeyAttr=>[]);
$data = $xml->XMLin("OnlineCinema.xml");
print "Content-type: text/html \n\n";
foreach $e (@{$data->{Cinema}}) {
print "City: ", $e->{City}, "</br>\n";
print "Name: ", $e->{Name}, "</br>\n";
print "</br></br>\n";
}