Does it mean source and result should both be either DOM or Stream or SAX and not mixed?

Discussion in 'XML' started by moralbarometer, Mar 1, 2007.

  1. Hi all,
    I intend to retrieve the fault node as a a string from the soap
    message. When i used transform(DOMSource,StreamResult) i get just the
    <?xml version="1.0" encoding="UTF-8"?>
    as string. but when i use transform(StreamSource,StreamResult) i get
    the expected String of fault Node.
    where am i wrong?. transform(DOMSource,StreamResult) and
    transform(StreamSource,StreamResult) are they different . Does it mean
    source and result should both be either DOM or Stream or SAX and not
    mixed?
    See information below
    public String doSerialization(Message soapMsg)
    {
    StreamSource sourceXSL=new
    StreamSource(Thread.currentThread().getClass()
    .getClassLoader().getResourceAsStream("de/
    AxisFaultProcessor.xsl"));

    DOMSource domSource=new
    DOMSource(soapMsg.getSOAPEnvelope().getAsDocument());

    ByteArrayOutputStream out=new ByteArrayOutputStream();

    StreamResult streamResult=new StreamResult(out);

    TransformerFactory transformerFactory
    =TransformerFactory.newInstance();

    Transformer transformer
    =transformerFactory.newTransformer(sourceXSL);

    transformer.setParameter("action",
    "serializeAxisFaultFromSOAPEnvelope");
    transformer.setOutputProperty("method", "xml");
    transformer.transform(domSource, streamResult);

    return out.toString();
    }




    /// XSL below

    <?xml version="1.0"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
    Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" >
    <xsl:param name="action" />
    <xsl:template match="/">
    <xsl:choose>
    <xsl:when test="$action='serializeAxisFaultFromSOAPEnvelope'">
    <xsl:copy-of select="soap:Envelope/soap:Body/soap:fault"/>
    </xsl:when>
    <xsl:eek:therwise>
    </xsl:eek:therwise>
    </xsl:choose>
    </xsl:template>


    </xsl:stylesheet>
     
    moralbarometer, Mar 1, 2007
    #1
    1. Advertising

  2. Re: Does it mean source and result should both be either DOM or Streamor SAX and not mixed?

    moralbarometer wrote:
    > When i used transform(DOMSource,StreamResult)


    Mixing these should be no problem, so I'm presuming the error is
    something else, such as a DOM that isn't providing information this XSLT
    processor needs.

    Are you absolutely sure soapMsg is a namespace-aware DOM Level 2 DOM
    instance? (That is, do the elements have namespaces and localnames, or
    only node names?)

    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Mar 1, 2007
    #2
    1. Advertising

  3. Re: Does it mean source and result should both be either DOM or Stream or SAX and not mixed?

    Hi Joe,
    thx for the prompt reply. see below the
    i have used for testing the xml below:

    <?xml version='1.0' ?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <soap:fault>
    <soap:code>
    <soap:value>X90</soap:value>
    <soap:subcode>
    <soap:value>Y90</soap:value>
    </soap:subcode>
    </soap:code>
    <soap:reason>
    <soap:text>remote exception occurred during this period</soap:text>
    <soap:text>This reason has been logged in our system for further
    references please consult with the number ID</soap:text>
    </soap:reason>
    <soap:detail>
    <message>3-Piece luggage set. Black Polyester</message>
    <id>100</id>
    </soap:detail>
    </soap:fault>
    </soap:Body>
    </soap:Envelope>
     
    moralbarometer, Mar 1, 2007
    #3
  4. Re: Does it mean source and result should both be either DOM or Streamor SAX and not mixed?

    That isn't what I asked. Yes, your input document uses namespaces. Does
    the DOM display them correctly? If not, whatever's building the DOM has
    to be fixed.
     
    Joseph Kesselman, Mar 1, 2007
    #4
  5. Re: Does it mean source and result should both be either DOM or Stream or SAX and not mixed?

    the code below shows how i created the DOMSource
    Is there any error in it?
    thx

    InuputStream confiXML=StreamSource(Thread.currentThread().getClass()
    .getClassLoader().getResourceAsStream("de/
    SOAP.xml"));

    DocumentBuilderFactory
    documentBuilderFactory=DocumentBuilderFactory.newInstance();
    DocumentBuilder
    documentBuilder=documentBuilderFactory.newDocumentBuilder();
    Document document=documentBuilder.parse(confiXML);
    DOMSource domSource=new DOMSource(document);
     
    moralbarometer, Mar 1, 2007
    #5
  6. Re: Does it mean source and result should both be either DOM or Streamor SAX and not mixed?

    moralbarometer wrote:
    > the code below shows how i created the DOMSource
    > Is there any error in it?
    > thx
    >
    > InuputStream confiXML=StreamSource(Thread.currentThread().getClass()
    > .getClassLoader().getResourceAsStream("de/
    > SOAP.xml"));
    >
    > DocumentBuilderFactory
    > documentBuilderFactory=DocumentBuilderFactory.newInstance();


    // Add this line. (Arguably should be the default these days, but
    // generally isn't for historical reasons of compatability with
    // ancient code.)
    documentBuilderFatory.setNamespaceAware(true);


    > DocumentBuilder
    > documentBuilder=documentBuilderFactory.newDocumentBuilder();
    > Document document=documentBuilder.parse(confiXML);
    > DOMSource domSource=new DOMSource(document);




    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Mar 1, 2007
    #6
  7. Re: Does it mean source and result should both be either DOM or Streamor SAX and not mixed?

    Joseph Kesselman wrote:
    > documentBuilderFatory.setNamespaceAware(true);


    Should of course have been ...Factory.set...

    (Sorry. Free, typo-free, useful; pick any two.)

    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
     
    Joseph Kesselman, Mar 1, 2007
    #7
  8. Re: Does it mean source and result should both be either DOM or Stream or SAX and not mixed?

    Hallo Joe,
    Thanks alot. it works well.
    have a nice weekend
     
    moralbarometer, Mar 2, 2007
    #8
  9. Re: Does it mean source and result should both be either DOM or Stream or SAX and not mixed?

    Hi all,
    is namespace enabled when retreiving document from SOAPMessage.
    AXIS is used in this case. As shown below
    DOMSource domSource=new
    DOMSource(soapMsg.getSOAPEnvelope().getAsDocument());
    thanks
     
    moralbarometer, Mar 5, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Collin VanDyck

    Create DOM from SAX stream

    Collin VanDyck, Dec 8, 2004, in forum: Java
    Replies:
    1
    Views:
    514
    Alan Gutierrez
    Dec 9, 2004
  2. Replies:
    1
    Views:
    375
    [Si]dragon
    Apr 11, 2006
  3. Collin VanDyck

    Create DOM from SAX stream

    Collin VanDyck, Dec 8, 2004, in forum: XML
    Replies:
    0
    Views:
    614
    Collin VanDyck
    Dec 8, 2004
  4. Owen Jacobson

    Unclear on either EJB3 or JBoss or both

    Owen Jacobson, Jul 21, 2006, in forum: Java
    Replies:
    0
    Views:
    353
    Owen Jacobson
    Jul 21, 2006
  5. Michael Tan
    Replies:
    32
    Views:
    1,030
    Ara.T.Howard
    Jul 21, 2005
Loading...

Share This Page