gackles has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to access the attributes in an incoming message to my soap server. I can get any tagged elements but everything I try - even data dumper - cannot access the attributes. Here's the incoming message. You can see the Section tag has the 'type' attribute and the Entity tags have the name,sectionEntityMapId,and value attributes and nothing else. I need to get to these attributes but nothing I've tried is working. I really appreciate any help.

<sendMsg2ABC><Request_Update_Message><Action>APPROVE</Action><Request_ +Id>999999</Request_Id><NegotiatorName>MICHELLE</NegotiatorName><Negot +iatorPhone>800-555-5555</NegotiatorPhone><VtacContactName>CYNTHIA</Vt +acContactName><VtacContactPhone>555-555-5555</VtacContactPhone><Reque +stType>CHANGE</RequestType><RequestStatus>PENDING</RequestStatus><Iss +uedDate>12/10/2015 09:29:02 AM</IssuedDate><Section type="A"><Entity +name="requestdate" sectionEntityMapId="176" value="12/14/2015"/><Enti +ty name="servicetype" sectionEntityMapId="177" value="LOCAL"/><Entity + name="npanxx" sectionEntityMapId="178" value="732270"/><Entity name= +"host" sectionEntityMapId="179" value="NJ01D5"/><Entity name="clli" s +ectionEntityMapId="182" value="NJ01D5"/><Entity name="area" sectionEn +tityMapId="183" value="NJ"/><Entity name="nodetype" sectionEntityMapI +d="184" value="100"/><Entity name="serviceorders" sectionEntityMapId= +"185" value="R622"/><Entity name="englishname" sectionEntityMapId="18 +6" value="EAST NOWHERE"/><Entity name="ratecenter" sectionEntityMapId +="8045" value="TOMS HOUSE"/></Section><Section type="B"><Entity name= +"customername" sectionEntityMapId="188" value="USA"/><Entity name="ad +dress" sectionEntityMapId="189" value="857 Big Road"/><Entity name="c +ity" sectionEntityMapId="190" value="EAST NOWHERE"/><Entity name="sta +te" sectionEntityMapId="191" value="NJ"/><Entity name="customercontac +t" sectionEntityMapId="192" value="MORGAN"/><Entity name="contactnumb +er" sectionEntityMapId="193" value="555-555-5555"/><Entity name="main +phone" sectionEntityMapId="194" value="555-555-5555"/><Entity name="T +LI" sectionEntityMapId="195" value="555-555-7000"/><Entity name="rems +tationrange" sectionEntityMapId="201" value="555-555-7000"/><Entity n +ame="numoflinesrem" sectionEntityMapId="202" value="1"/><Entity name= +"port" sectionEntityMapId="203" value="N"/><Entity name="pset" sectio +nEntityMapId="206" value="N"/><Entity name="special" sectionEntityMap +Id="207" value="N"/><Entity name="tg" sectionEntityMapId="209" value= +"0615"/><Entity name="rti" sectionEntityMapId="210" value="NA"/><Enti +ty name="remarks" sectionEntityMapId="212" value="NO WORK; SAME DATE +FOR PORT; THANKS"/></Section><Section type="N"><Entity name="swc" sec +tionEntityMapId="217" value="732555"/><Entity name="wirecenter" secti +onEntityMapId="218" value="EAST NOWHERE"/><Entity name="serviceorders +" sectionEntityMapId="219" value="R6622"/><Entity name="vremarks" sec +tionEntityMapId="222" value="No Work Required]"/></Section></Request_ +Update_Message></sendMsg2ABC>

Replies are listed 'Best First'.
Re: Accessing Attributes in Web Servie message - Server Side
by RichardK (Parson) on Feb 18, 2016 at 16:06 UTC

    So what are you using to parse the XML? Try showing us some (minimal) code!

      Here is my SOAP server:

      #!/usr/bin/perl use strict; use SOAP::Transport::HTTP; use lib '/var/www/soap'; use vbsservice; my $server = SOAP::Transport::HTTP::CGI ->dispatch_to('sendMsg2ABC') ->handle; 1;

      Here is the vbsservice module:

      #!/usr/local/bin/perl package vbsservice; use Switch; use warnings; use Exporter; our @ISA = (Exporter); our @EXPORT = qw(sendMsg2ABC); sub sendMsg2ABC { my($class,$data)=@_; ...

      $data is a hash ref that I've parsed all sorts of ways but I'm never able to get to the attributes of the incoming message. I can easily parse the key/values from any tag/element entries of the message but not the attributes. One thing I'm trying now is the dataof method but I haven't been able to get that to work. As a note, I cannot change the way the message is coming in. That's out of my control. Thank you again for any help.

        What is the structure of $data if you use Dumper

        use Data::Dumper; sub sendMsg2ABC { my($class,$data)=@_; print Dumper $data;
        poj
Re: Accessing Attributes in Web Servie message - Server Side
by gackles (Novice) on Feb 29, 2016 at 16:21 UTC
    I appreciate everyone's suggestions. Nothing is working. Most solutions rely on an xml file or a data object. The data that reaches my package is simply a hash ref not a data object. I trying walking through the hash/array/hash to pull attributes without success. So a few questions: - Is there a way to capture the untouched raw message that is coming in? - Is this a serialization issue? If so how can I deserialize the data? - Can I force the data coming in to be recognized as a data object (any attempts to reference the methods of the incoming data give me errors.) - Is there a way to pass the hash ref to xml:twig/simple or other mods without creating a file? Thanks to anyone who can help me.

      - Is there a way to capture the untouched raw message that is coming in?

      Yes, read from STDIN , be first

      - Is this a serialization issue? If so how can I deserialize the data?

      No, not serialization

      - Can I force the data coming in to be recognized as a data object (any attempts to reference the methods of the incoming data give me errors.)

      Its hard to see your code to know what you're talking about.

      So far you've gotten adequate responses to answer both your questions, you just have to put it all together, and present everything relevant when you get stuck.

      If you find yourself saying tried that but it didn't work substitute that with code that shows it doesn't work.

      - Is there a way to pass the hash ref to xml:twig/simple or other mods without creating a file?

      Yes, the docs explain how, they have code examples and word explanations

        Thank you Thank you Thank you. I'm using the STDIN to grab the raw data and parse it. I had no idea I could do that. My new problem is sending back a message to the client. If I just "print $xml" where $xml is the STDIN message, it works. If I want to send something else back it doesn't work. How do I send a customized message back to the client if I'm using STDIN to receive the message?