Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

SOAP string conversion problem

by Hammy (Scribe)
on Sep 20, 2004 at 17:32 UTC ( [id://392429]=perlquestion: print w/replies, xml ) Need Help??

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

Hello, I have been given a heck of a lot of good information and documentation for my SOAP problems to date so thank you. I have very strange behavior when converting a string to soap and I am hoping someone has seen this before. The code is simple:
$xml = '<wellmed>MessageList><MessageItem msgtype="5" subject="Bookmar +k from Health Coach"><Patient loginname="' ."$ss|$name|$dob" . '" spo +nsorid="303" /><DocumentList><DocumentItem date="' . "$theDate" .'" f +rom="HealthDialog" time="">abc</DocumentItem></DocumentList></Message +Item></MessageList></wellmed>'; use XML::Simple; use SOAP::Lite +trace; my $data = SOAP::Data->name('data' => "$xml")->type('string')->uri('') +;
I would expect all '<' characters to be turned to '& l t ;' and all '>' characters to be turned to '& g t ;' (I put in the spaces here because it converts them for display). It converts the '<', but not the '>'. I can not fathom why it converts one type and not the other. Here is the trace:
<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-EN +C="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle= +"http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://sc +hemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/X +MLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"><SOAP +-ENV:Body><namesp1:PerformUpdate xmlns:namesp1="http://di.wellmed.com +/SoapService"><data xmlns="" xsi:type="xsd:string">&lt;wellmed>Messag +eList>&lt;MessageItem msgtype="5" subject="Bookmark from Health Coach +">&lt;Patient loginname="111111111|LYNN|19407202" sponsorid="303" />& +lt;DocumentList>&lt;DocumentItem date="09/17/04" from="HealthDialog" +time="">abc&lt;/DocumentItem>&lt;/DocumentList>&lt;/MessageItem>&lt;/ +MessageList>&lt;/wellmed></data></namesp1:PerformUpdate></SOAP-ENV:Bo +dy></SOAP-ENV:Envelope>
Thank You

Replies are listed 'Best First'.
Re: SOAP string conversion problem
by bpphillips (Friar) on Sep 20, 2004 at 18:38 UTC
    From the SOAP/Lite.pm file (line #349 in my version):
    # Q: why only '&' and '<' are encoded, but not '>'? # A: because it is not required according to XML spec. # # [http://www.w3.org/TR/REC-xml#syntax] # The ampersand character (&) and the left angle bracket (<) may appea +r in # their literal form only when used as markup delimiters, or within a +comment, # a processing instruction, or a CDATA section. If they are needed els +ewhere, # they must be escaped using either numeric character references or th +e # strings "&amp;" and "&lt;" respectively. The right angle bracket (>) + may be # represented using the string "&gt;", and must, for compatibility, be + # escaped using "&gt;" or a character reference when it appears in t +he # string "]]>" in content, when that string is not marking the end of +a # CDATA section.
      Thanks you very much that answers my question - The service is having a problem retrieving this info with the '>' not being encoded, but it appears (as it usually does) that Perl is doing what it should. Thank you again for your help!
Re: SOAP string conversion problem
by ikegami (Patriarch) on Sep 20, 2004 at 17:51 UTC

    Parsers will ignore closing tags if they haven't seen an opening tag. I don't know if taking the shortcut you mention is legal, but it will probably work fine.

    btw, the proper way to write &lt; in HTML is &amp;lt;, as opposed to & l t ;.

      Thanks for getting back to me so quickly. I am not sure what shortcut I took. As for ignoring closing tags - the opening tags are there, the parser just converts them. How do I get it to recognize and convert both tags?

        I was trying to say the > don't need to be escaped because &lt;...> will not be confused as <...>. The library takes the shortcut of not escaping >s to save time and to reduce the size of the output.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://392429]
Approved by ikegami
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2024-04-23 14:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found