Question

So the responses are basically full XML documents escaped as a string inside of another XML Document. What is the best way to extract this String and Parse it into something I can simply get the values from.

(will accept simply how to get it back to raw XML)

  <soap:Body>
    <DoItUsernamePwdResponse xmlns="http://www.aspdotnetstorefront.com/">
      <DoItUsernamePwdResult>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;AspDotNetStorefrontImportResult Version="9.2" DateTime="9/18/2013 1:46:06 PM"&gt;&lt;Item NodeType="Entity" Name="Nike" GUID="84775261-731D-4E11-BB82-FA5F61BC61C5" ID="1" ActionTaken="Add" Status="OK" Message="" /&gt;&lt;/AspDotNetStorefrontImportResult&gt;</DoItUsernamePwdResult>
    </DoItUsernamePwdResponse>
  </soap:Body>
Was it helpful?

Solution

Just fetch the textual value of the DoItUsernamePwdResult element (e.g. using findnodes) and just feed the result again into the XML::LibXML parser. Something like this could work:

use strict;
use XML::LibXML;

my $xmlxml = <<'EOF';
  <soap:Body xmlns:soap="something">
    <DoItUsernamePwdResponse xmlns="http://www.aspdotnetstorefront.com/">
      <DoItUsernamePwdResult>&lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;AspDotNetStorefrontImportResult Version="9.2" DateTime="9/18/2013 1:46:06 PM"&gt;&lt;Item NodeType="Entity" Name="Nike" GUID="84775261-731D-4E11-BB82-FA5F61BC61C5" ID="1" ActionTaken="Add" Status="OK" Message="" /&gt;&lt;/AspDotNetStorefrontImportResult&gt;</DoItUsernamePwdResult>
    </DoItUsernamePwdResponse>
  </soap:Body>
EOF

my $xml = XML::LibXML->new->parse_string($xmlxml)->findvalue('//*[local-name()="DoItUsernamePwdResult"]');
warn XML::LibXML->new->parse_string($xml)->serialize;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top