Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Does it mean source and result should both be either DOM or Stream or SAX and not mixed? (http://www.velocityreviews.com/forums/t399699-does-it-mean-source-and-result-should-both-be-either-dom-or-stream-or-sax-and-not-mixed.html)

moralbarometer 03-01-2007 09:51 AM

Does it mean source and result should both be either DOM or Stream or SAX and not mixed?
 
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:otherwise>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


</xsl:stylesheet>


Joe Kesselman 03-01-2007 01:07 PM

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

moralbarometer 03-01-2007 02:59 PM

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>


Joseph Kesselman 03-01-2007 04:26 PM

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.

moralbarometer 03-01-2007 05:03 PM

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().getCl ass()
.getClassLoader().getResourceAsStream("de/
SOAP.xml"));

DocumentBuilderFactory
documentBuilderFactory=DocumentBuilderFactory.newI nstance();
DocumentBuilder
documentBuilder=documentBuilderFactory.newDocument Builder();
Document document=documentBuilder.parse(confiXML);
DOMSource domSource=new DOMSource(document);


Joseph Kesselman 03-01-2007 05:45 PM

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().getCl ass()
> .getClassLoader().getResourceAsStream("de/
> SOAP.xml"));
>
> DocumentBuilderFactory
> documentBuilderFactory=DocumentBuilderFactory.newI nstance();


// 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.newDocument Builder();
> Document document=documentBuilder.parse(confiXML);
> DOMSource domSource=new DOMSource(document);




--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden

Joseph Kesselman 03-01-2007 10:57 PM

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

moralbarometer 03-02-2007 06:42 PM

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 03-05-2007 09:35 AM

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



All times are GMT. The time now is 03:45 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57