This is a very odd approach to parsing XML. Is there no other effective XML module that you can use, such as XML::Twig
?
SOAP::SOM
expects something more than bare XML in the parameter to its constructor. It is normally created by accessing a remote SOAP server using SOAP::Lite
.
You need to use SOM::Deserializer
, like this
use strict;
use warnings;
use SOAP::Lite;
my $cust_xml = <<'__END_XML__';
<CUSTOMER_RESPONSE>
<CUSTOMER>
<TEL>555-555-5555</TEL>
</CUSTOMER>
<PRODUCTS>
<PRODUCT>
<PRODUCT_ID>Apple</PRODUCT_ID>
</PRODUCT>
<PRODUCT>
<PRODUCT_ID>BlackBerry</PRODUCT_ID>
</PRODUCT>
<PRODUCT>
<PRODUCT_ID>Orange</PRODUCT_ID>
</PRODUCT>
</PRODUCTS>
</CUSTOMER_RESPONSE>
__END_XML__
my $som = SOAP::Deserializer->deserialize($cust_xml);
print "$_\n" for $som->valueof('//PRODUCT_ID');
output
Apple
BlackBerry
Orange