Hi,

Turns out it is possible to transform an XML file or a Xerces-c DOMDocument 
into a Xerces-c Document. in fact, a sample in the Xalan-C++ distribution shows 
how to do it. I have implemented methods in a XalanTransform wrapper class that 
support transforming an XML file and a Xerce-c DOMDocument into a Xerces-c 
DOMDocument (see below). Both methods work just fine.

Regards,

Paul

   Document* Transformer::transform(Document *pInDoc) const {
        XMLPlatformUtils::Initialize();

        std::unique_ptr<XercesParserLiaison> parserLiaisonPtr(new 
XercesParserLiaison());
        std::unique_ptr<XercesDOMSupport> xercesDOMSupportPtr(new 
XercesDOMSupport(*parserLiaisonPtr.get()));

        XalanDocument *pXalanDoc = 
parserLiaisonPtr->createDocument(pInDoc->getImpl());
        const xalanc::DOMDocument_Type *pXercesDoc = 
parserLiaisonPtr->mapToXercesDocument(pXalanDoc);

        std::unique_ptr<XercesDOMWrapperParsedSource>  pSrc(
            new XercesDOMWrapperParsedSource(pXercesDoc, *parserLiaisonPtr, 
*xercesDOMSupportPtr));

        Document *pOutDoc = new Document();
        FormatterToXercesDOM formatter(pOutDoc->getImpl(), 0);

        try {
            if (_pXalanTransformer->transform(*pSrc, _pSS, formatter))
            {
                XML_TRANSFORM_ERROR2(xformrXFormError, "document", 
_pXalanTransformer->getLastError());
            }
        }
        catch (...) {
            XML_TRANSFORM_ERROR1(xformrUnknownXFormError, "document");
        }
        return pOutDoc;
    }

From: Paul Kinnucan
Sent: Tuesday, August 11, 2020 8:44 PM
To: c-users@xalan.apache.org
Subject: RE: Transforming xerces-c::DOMDocument into a xerces-c::DOMDocument

Hi Roger,

Thanks for the prompt response.

I am porting an XML API that wraps  JAXP to an API that wraps xerce-c/xalan-c 
to eliminate the wrapper API's dependency on Java. The API includes wrappers 
around the JAXP DOMSource and StreamSource and JAXP  DOMResult classes. Xalan-c 
appears to have equivalents for the JAXP DOMSource and  StreamSource classes 
but no direct equivalent for DOMResult. A workaround for DOMResult might be a 
class that streams the transform result to the Xerces-c parser and returns the 
result.

Regards,

Paul


From: Roger Leigh <rle...@codelibre.net<mailto:rle...@codelibre.net>>
Sent: Tuesday, August 11, 2020 6:23 PM
To: c-users@xalan.apache.org<mailto:c-users@xalan.apache.org>
Subject: Re: Transforming xerces-c::DOMDocument into a xerces-c::DOMDocument


Hi Paul,



I would love to be proven wrong, but I'm fairly sure this isn't possible, 
because I would have loved to have been able to do this in my own projects 
where multiple transforms needed applying to a DOMDocument in sequence and 
spent quite some time investigating it.  I imagine that this limitation stems 
from the result of the transform being potentially in any format possible: 
plain text, JSON, YAML, HTML, XHTML, XML etc.  So XSLTResultTarget is fairly 
limited in allowing only streaming output.



Kind regards,

Roger


On 11/08/2020 21:55, Paul Kinnucan wrote:
Hi,

Does xalan-c support transforming a xerces-c::DOMDocument into another 
xerces-c::DOMDocument?

The xalan-c API doc indicates that you can transform a xerces-c::DOMDocument 
into a file or output stream. Specifically, an XSLInputSource can be a
xalan-c::XercesDOMWrapperParsedSource<https://apache.github.io/xalan-c/api/classxalanc_1_1XercesDOMWrapperParsedSource.html#a99ba70ee0bc25196712711a5a41967b4>.

But I don't see any variant of the transform method that would result in a 
xerces-c::DOMDocument, i.e., an XSLTResultTarget can only be a file or a stream.

Is it possible to stream the transform output to the Xerces parser to get a 
xerces-c::DOMDocument as a transform result?

Regards,

Paul

Reply via email to