0

我有一个如下的 XML$response_xml

<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;wholeSaleApi&gt;&lt;credentials&gt;&lt;referenceNumber&gt;&lt;/referenceNumber&gt;&lt;/credentials&gt;&lt;wholeSaleOrderResponse&gt;&lt;statusCode&gt;666&lt;/statusCode&gt;&lt;description&gt;Object reference not set to an instance of an object.&lt;/description&gt;&lt;/wholeSaleOrderResponse&gt;&lt;/wholeSaleApi&gt;</string>

当我使用解析它时

my $xs = XML::Simple->new();
my $xmlDS = eval{ $xs->XMLin($response_xml) };

我得到以下数据结构

$xmlDS =  {
          'xmlns' => 'http://schemas.microsoft.com/2003/10/Serialization/',
          'content' => '<?xml version="1.0" encoding="utf-8"?><wholeSaleApi><credentials><referenceNumber></referenceNumber></credentials><wholeSaleOrderResponse><statusCode>666</statusCode><description>Object reference not set to an instance of an object.</description></wholeSaleOrderResponse></wholeSaleApi>'
        };

我如何从中获得content部分?

4

1 回答 1

3

你得到的是一个哈希引用。您可以使用以下语法来获取特定键:

my $content = $xmlDS->{content};
于 2013-06-10T11:34:02.877 回答