[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XML Parsing with Encoded Characters



   Thanks Scott!  That got it working.
   Scott Klement wrote:

Hi Alan,

To add some context to the message you quoted.  The person who asked the 
question was retrieving their SOAP message with http_url_post_xml().

It was the same symptom as you describe... but when http_url_post_xml() 
calls the end-element-handler for the <soap:Body> element, it provides a 
'value' that contains the entire XML document, with the &lt;, &gt;, etc 
already decoded.

If you then take the value from soap:Body, treat it as a new XML 
document, and decode it a second time with http_xml_parse_stmf() or 
http_xml_parse_string() you'll get the answer you're looking for.

There's an example of this here:
[1]http://www.scottklement.com/httpapi/bankrout.txt

Good luck


On 3/1/2011 9:15 AM, Alan Smith wrote:


    I'm downloading a SOAP message from a webservice where the body
    contains an xml document.  The xml tags (<  >) within the body of the
    message are being escaped.  This is causing a problem with the xml
    parser.  While searching for an answer as to how to handle this, I
    came across another thread on this mailing list where Scott explained
    how to handle the situation.  This is from the other thread:
<soap:Envelope whatever-whatever>
    <soap:Body whatever>
      &lt;ADStart&gt;&lt;error code="0" text="NO_ERROR"
      /&gt;&lt;ticket&gt;fe81cb7e-fd9e-411b-b3fd-b9c5729728f7
      &lt;/ticket&gt;&lt;/ADStart&gt;
    </soap:Body>
</soap:Envelope>

What I mean is... are the<,>  and&  characters escaped so that they
won't be treated as XML tags, as they are in the above example?  If so,
that's a very common issue.  The solution is to have the contents of the
'Body' element saved to a file (or a string if it's small enough) and
then parse that file/string separately using http_parse_xml_stmf() or
http_parse_xml_string()

    I've taken the body portion of the message and placed it into a
    separate streamfile and am using http_parse_xml_stmf() to parse that
    file.   However, this still doesn't work.  Should the xml tags be
    un-escaped in order for the parser work?  Or is there another
    solution?
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
[2]http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------



-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
[3]http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------

References

   1. http://www.scottklement.com/httpapi/bankrout.txt
   2. http://www.scottklement.com/mailman/listinfo/ftpapi
   3. http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------