Java XML Format printReply(SOAPMessage reply)

Here you can find the source of printReply(SOAPMessage reply)

Description

print reply to output to System.out

License

Common Public License

Declaration

public static void printReply(SOAPMessage reply) throws SOAPException 

Method Source Code

//package com.java2s;
/*/*from   w  ww .  j ava  2s .  c  o m*/
 * ====================================================================
 * This software is subject to the terms of the Common Public License
 * Agreement, available at the following URL:
 *   http://www.opensource.org/licenses/cpl.html .
 * Copyright (C) 2003-2004 TONBELLER AG.
 * All Rights Reserved.
 * You must accept the terms of that agreement to use this software.
 * ====================================================================
 *
 * 
 */

import java.util.Iterator;

import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPException;

import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;

public class Main {
    /**
     * print reply to output to System.out
     */
    public static void printReply(SOAPMessage reply) throws SOAPException {
        // Document source, do a transform.
        System.out.println("Reply:");
        SOAPPart sp = reply.getSOAPPart();
        SOAPEnvelope envelope = sp.getEnvelope();
        SOAPBody body = envelope.getBody();
        Iterator itBody = body.getChildElements();
        while (itBody.hasNext()) {
            SOAPElement element = (SOAPElement) itBody.next();
            printElement(element);
        }
        System.out.println();
    }

    /**
     * recursively print element
     * @param el
     */
    static private void printElement(SOAPElement el) {

        System.out.println(el.getElementName() + el.getValue());
        Iterator itAtt = el.getAllAttributes();
        if (itAtt.hasNext()) {
            System.out.print("<" + el.getElementName());
            while (itAtt.hasNext()) {
                SOAPElement att = (SOAPElement) itAtt.next();
                System.out.print(" " + att.getElementName() + "=" + att.getValue());
            }
            System.out.println(">");
        } else {
            System.out.println("<" + el.getElementName() + ">");
        }

        System.out.println(el.getValue());
        System.out.println("</" + el.getElementName() + ">");

        Iterator it = el.getChildElements();
        while (it.hasNext()) {
            SOAPElement element = (SOAPElement) it.next();
            printElement(element);
        }
    }
}

Related

  1. printNode(Node node)
  2. printNode(Node node, String fn)
  3. printNode(OutputStream out, Node node, boolean prettyPrint, boolean includeXmlDeclaration)
  4. printNodeSubtreeXMLString(final Node node)
  5. printNodeToConsole(Node n, ByteArrayOutputStream byteArrayOS)
  6. printStream(InputStream is)
  7. printXML(Node node)
  8. xmlFormat(String xml)
  9. xmlFormat(String xml)