Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   Oracle XSLProcessor returns an XMLDocumentFragment and I need anXMLDocument (or XMLType) (or even String) (http://www.velocityreviews.com/forums/t680190-oracle-xslprocessor-returns-an-xmldocumentfragment-and-i-need-anxmldocument-or-xmltype-or-even-string.html)

Stryder 04-16-2009 05:12 PM

Oracle XSLProcessor returns an XMLDocumentFragment and I need anXMLDocument (or XMLType) (or even String)
 
I'm trying to do something that should be simple. In Oracle 11g, I'm
trying to write a Java stored procedure that applies an XSLT
stylesheet to an XML document and returns it as type XMLType.

Here's a snippet that shows the question...

public static XMLType bwdtransform(oracle.sql.CLOB documentText)
throws Exception {
// ==============================
// This works - oracle.xml.parser.v2.DOMParser parses the incoming
CLOB into an
// oracle.xml.parser.v2.XMLDocument
// ==============================
parser.parse(documentText.getCharacterStream());
XMLDocument xmlDocument = (XMLDocument) parser.getDocument();

// ==============================
// This works - applies adopterXSLT, which is a
oracle.xml.parser.v2.XSLStylesheet,
// to the XMLDocument, returning an XMLDocumentFragment. It'd
solve the problem
// if this could return an XMLDocument, but it doesn't
// ==============================
XMLDocumentFragment xmlDocumentFragment = processor.processXSL
(adopterXSLT, xmlDocument);

// ==============================
// This DOES NOT work. XMLType requires an XMLDocument, not an
XMLDocumentFragment
// as its second parameter. I can find no way to translate an
XMLDocumentFragment into
// an XMLDocument, an XMLType, or even serialize it to a string.
// ==============================
return new XMLType(conn, xmlDocumentFragment);
}

Any help in returning the result of applying the stylesheet as an
XMLType would be very
very greatly appreciated.

Thanks.

Ralph

Martin Honnen 04-16-2009 05:36 PM

Re: Oracle XSLProcessor returns an XMLDocumentFragment and I needan XMLDocument (or XMLType) (or even String)
 
Stryder wrote:
> I'm trying to do something that should be simple. In Oracle 11g, I'm
> trying to write a Java stored procedure that applies an XSLT
> stylesheet to an XML document and returns it as type XMLType.
>
> Here's a snippet that shows the question...
>
> public static XMLType bwdtransform(oracle.sql.CLOB documentText)
> throws Exception {
> // ==============================
> // This works - oracle.xml.parser.v2.DOMParser parses the incoming
> CLOB into an
> // oracle.xml.parser.v2.XMLDocument
> // ==============================
> parser.parse(documentText.getCharacterStream());
> XMLDocument xmlDocument = (XMLDocument) parser.getDocument();
>
> // ==============================
> // This works - applies adopterXSLT, which is a
> oracle.xml.parser.v2.XSLStylesheet,
> // to the XMLDocument, returning an XMLDocumentFragment. It'd
> solve the problem
> // if this could return an XMLDocument, but it doesn't
> // ==============================
> XMLDocumentFragment xmlDocumentFragment = processor.processXSL
> (adopterXSLT, xmlDocument);


Does
XMLDocument doc = (XMLDocument)xmlDocumentFragment.getOwnerDocument( );
give you an object? Or is that null? If it is not null and is an empty
document then you could simply do
doc.appendChild(xmlDocumentFragment);
assuming your XSLT stylesheet does indeed create a document with a
single root element.
Or create a new document
XMLDocument doc = new XMLDocument();
and do
doc.appendChild(doc.adoptNode(xmlDocumentFragment) );



--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/

Stryder 04-16-2009 06:22 PM

Re: Oracle XSLProcessor returns an XMLDocumentFragment and I need anXMLDocument (or XMLType) (or even String)
 
On Apr 16, 1:36*pm, Martin Honnen <mahotr...@yahoo.de> wrote:
> Stryder wrote:
> > I'm trying to do something that should be simple. *In Oracle 11g, I'm
> > trying to write a Java stored procedure that applies an XSLT
> > stylesheet to an XML document and returns it as type XMLType.

>
> > Here's a snippet that shows the question...

>
> > public static XMLType bwdtransform(oracle.sql.CLOB documentText)
> > throws Exception {
> > * * // ==============================
> > * * // This works - oracle.xml.parser.v2.DOMParser parses the incoming
> > CLOB into an
> > * * // oracle.xml.parser.v2.XMLDocument
> > * * // ==============================
> > * * parser.parse(documentText.getCharacterStream());
> > * * XMLDocument xmlDocument = (XMLDocument) parser.getDocument();

>
> > * * // ==============================
> > * * // This works - applies adopterXSLT, which is a
> > oracle.xml.parser.v2.XSLStylesheet,
> > * * // to the XMLDocument, returning an XMLDocumentFragment. *It'd
> > solve the problem
> > * * // if this could return an XMLDocument, but it doesn't
> > * * // ==============================
> > * * XMLDocumentFragment xmlDocumentFragment = processor.processXSL
> > (adopterXSLT, xmlDocument);

>
> Does
> * *XMLDocument doc = (XMLDocument)xmlDocumentFragment.getOwnerDocument( );
> give you an object? Or is that null? If it is not null and is an empty
> document then you could simply do
> * doc.appendChild(xmlDocumentFragment);
> assuming your XSLT stylesheet does indeed create a document with a
> single root element.
> Or create a new document
> * *XMLDocument doc = new XMLDocument();
> and do
> * *doc.appendChild(doc.adoptNode(xmlDocumentFragment) );
>
> --
>
> * * * * Martin Honnen
> * * * *http://msmvps.com/blogs/martin_honnen/


The second option did it. Thank you thank you thank you.



All times are GMT. The time now is 05:51 AM.

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