Java Reference
In-Depth Information
Received SOAP reply:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap=" http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd=" http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetQuoteResponse xmlns=" http://www.webserviceX.NET/">
<GetQuoteResult>
&lt;StockQuotes&gt;&lt;Stock&gt;&lt;Symbol&gt;IBM&lt;
/Symbol&gt;&lt;Last&gt;196.40&lt;/Last&gt;&lt;Date&gt;
4/16/2014&lt;/Date&gt;&lt;Time&gt;4:01pm&lt;/Time&gt;
&lt;Change&gt;-
0.62&lt;/Change&gt;&lt;Open&gt;197.77&lt;/Open&gt;&lt;
High&gt;198.71&lt;/High&gt;&lt;Low&gt;195.00&lt;/Low&gt;
&lt;Volume&gt;8527415&lt;/Volume&gt;&lt;MktCap&gt;204.5B&lt;
/MktCap&gt;&lt;PreviousClose&gt;197.02&lt;/PreviousClose&gt;
&lt;PercentageChange&gt;-0.31%&lt;/PercentageChange&gt;&lt;
&gt;172.19 - 11.98&lt;/AnnRange&gt;&lt;Earns&gt;
14.942&lt;/Earns&gt;&lt;P-E&gt;13.19&lt;/P-E&gt;&lt;Name&gt;
International Bus&lt;/Name&gt;&lt;/Stock&gt;&lt;/StockQuotes&gt;
</GetQuoteResult>
</GetQuoteResponse>
</soap:Body>
</soap:Envelope>
Great! You seem to be getting something back now. However, as you can observe, this particu-
lar service has chosen to encode its result as one big mess within the GetQuoteResult tag. In
fact, the text included herein is a so‐called “escaped” XML string. Note how all the < and >
characters have been replaced with &lt ; and &gt ;. Why this particular server is behaving like
this instead of including the XML as is—which would be easier to parse—remains a mystery,
but to parse your result, you'll need to get out the escaped XML string and then interpret it
again as XML.
Note If you're paying very close attention, you might note that this SOAP
message still looks somewhat different from the example provided at the
WebserviceX.NET website. Most notable is that all your tags start with
SOAP-ENV , whereas the example uses soap . Funnily enough, the server
is not picky regarding this aspect. The reason for this is that a so‐called
“namespace” definition is explicitly provided in the message. In the exam-
ple provided, this is done by xmlns:soap=" http://schemas.xmlsoap.org/
soap/envelope/" . In your message, the same namespace is provided, but
with the name SOAP-ENV . A namespace is basically a way to indicate the
following: “Let's agree to use a set of tags we both know about. You can
find their definition and description on this URL, and I'm going to prepend
the tag names with SOAP-ENV .” As long as the server knows about the
namespace being used, it does not matter what shorthand name you use to
prepend the tags.
Search WWH ::




Custom Search