?
Solved

Formatting/Displaying a SOAP Reply Message (XML)

Posted on 2007-10-13
3
Medium Priority
?
926 Views
Last Modified: 2013-11-18
Hi Experts

I am writing a script (in PHP and Javascript) to communicate with a web service using SOAP requests. This works perfectly and has no problems.

What i was wondering is, when a message comes back from the soap request, how do I format it properly so that it can be displayed say for example in a table format or something alike? Applying some stylesheet to the soap message?

The SOAP message reply looks something like this:

#########
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Body>
    <message>
      <response from="gs2mgppdemo/TextQuery" type="process">
        <metadataList>
          <metadata name="numDocsMatched">45</metadata>
          <metadata name="numDocsReturned">10</metadata>
          <metadata name="query">apple</metadata>
        </metadataList>
        <documentNodeList>
          <documentNode docType="hierarchy" nodeID="HASH2e2c0786db13d242a0640e.5" nodeType="leaf" rank="61.874542" />
          <documentNode docType="hierarchy" nodeID="HASH9a32d65fe2d5e0559e9a88.6.3" nodeType="leaf" rank="30.937271" />
          <documentNode docType="hierarchy" nodeID="HASH01e114881a5545b979515a68.10.3" nodeType="leaf" rank="30.937271" />
          <documentNode docType="hierarchy" nodeID="HASH9a32d65fe2d5e0559e9a88.10.3" nodeType="leaf" rank="15.468636" />
          <documentNode docType="hierarchy" nodeID="HASH9a32d65fe2d5e0559e9a88.7.1" nodeType="leaf" rank="15.468636" />
          <documentNode docType="hierarchy" nodeID="HASH626d047760b154f868d2e5.7.1" nodeType="leaf" rank="15.468636" />
          <documentNode docType="hierarchy" nodeID="HASH01a99b6dc399591d12f46803.7.4" nodeType="leaf" rank="0.510514" />
          <documentNode docType="hierarchy" nodeID="HASH2e2c0786db13d242a0640e.6.5" nodeType="leaf" rank="0.20321295" />
          <documentNode docType="hierarchy" nodeID="HASH351102fcb484dbf644cd09.10.3" nodeType="leaf" rank="0.20321295" />
          <documentNode docType="hierarchy" nodeID="HASH626d047760b154f868d2e5.10.4" nodeType="leaf" rank="0.17838767" />
        </documentNodeList>
        <termList>
          <term field="" freq="54" name="apple" numDocsMatch="25" stem="3">
            <equivTermList>
              <term freq="" name="apples" numDocsMatch="" />
              <term freq="" name="applicant" numDocsMatch="" />
              <term freq="" name="Applied" numDocsMatch="" />
              <term freq="" name="applied" numDocsMatch="" />
              <term freq="" name="applies" numDocsMatch="" />
              <term freq="" name="Applying" numDocsMatch="" />
              <term freq="" name="applying" numDocsMatch="" />
            </equivTermList>
          </term>
        </termList>
      </response>
    </message>
  </soapenv:Body>
</soapenv:Envelope>
###########

I simply want to format the message so that it is displayable (doesn't even have to be too pretty with colours and sophisticated tables!).

Many thanks for your help!
0
Comment
Question by:nizsmo
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 2000 total points
ID: 20073033
You should use XSLT for that

try this

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <html>
            <body>
                <xsl:apply-templates select="//response"></xsl:apply-templates>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="response">
        <xsl:apply-templates select=".//termList"></xsl:apply-templates>
    </xsl:template>
    <xsl:template match="termList">
        <table border="1">
            <tr>
                <th>Term</th>
                <th>Frequency</th>
                <th>Matching Docs</th>
                <th>Stem</th>
                <th>Equivalent Terms</th>
            </tr>
            <xsl:apply-templates select=".//equivTermList/term"/>
        </table>
    </xsl:template>
    <xsl:template match="equivTermList/term">
        <xsl:param name="rspan" select="count(../term)" />
        <tr>
            <xsl:choose>
                <xsl:when test="position() = 1">
                    <td rowspan="{$rspan}"><xsl:value-of select="ancestor::term/@name"/></td>
                    <td rowspan="{$rspan}"><xsl:value-of select="ancestor::term/@freq"/></td>
                    <td rowspan="{$rspan}"><xsl:value-of select="ancestor::term/@numDocsMatch"/></td>
                    <td rowspan="{$rspan}"><xsl:value-of select="ancestor::term/@stem"/></td>
                    <td><xsl:value-of select="@name"/></td>
                </xsl:when>
                <xsl:otherwise>
                    <td><xsl:value-of select="@name"/></td>
                </xsl:otherwise>
            </xsl:choose>
           
        </tr>
    </xsl:template>
   
</xsl:stylesheet>

cheers

geert
0
 
LVL 21

Author Comment

by:nizsmo
ID: 20257716
sorry it took so long, i was quite busy, but thank you for your solution, it did get me started and i did learn a few things with this, thanks again.
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 20258467
welcome
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question