#!/usr/bin/perl -w use strict; use XML::Simple; my $text = <<xml; < ?xml version="1.0"? > <web-app> <servlet> <servlet-name>PHP</servlet-name> <servlet-class>net.PHP.servlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>PHP</servlet-name> <url-pattern>*.PHP</url-pattern> </servlet-mapping> </web-app> xml my $x = XMLin($text); foreach my $tag(keys %$x) { my %h = %{$$x{$tag}}; foreach(keys %h) { print "$tag => "; print "$_ => $h{$_}\n"; } } exit 0;原文链接:https://www.f2er.com/xml/295205.html