Greg,
Am unsure exactly what you output requirement is,
but in my case I _have_ to use the Xerces DOM as
output.
The code snippet I use is attached below. It
may not be the best way of doing things, but it
seems to work quite well for me. (I'm sure someone will tell me what I'm doing
wrong :>.)
The sb* elements are some objects I use for
manipulating buffers, so the rawCharBuffer() call
simply returns a pointer to a byte array.
BTW - I am using a recent CVS checked out version
of the Xalan source, so this will return the new
DOMNode type structures.
--SNIP--
// Set up iostreams for input
std::istrstream theXMLStream((char *) sbInDoc.rawBuffer(), strlen((char
*) sbInDoc.rawBuffer()));
std::istrstream theXSLStream((char *) sbStyleSheet.rawBuffer(),
strlen((char *) sbStyleSheet.rawBuffer()));
// Now resolve
XalanTransformer xt;
TransformXSLOutputHolder txoh;
txoh.buffer.sbStrcpyIn("");
txoh.offset = 0;
int res = xt.transform(&theXMLStream, &theXSLStream, (void *) & txoh,
TransformXSLOutputFn);
// Should check res
//std::cout.flush();
// Now use xerces to "re parse" this back into a DOMNodes document
XercesDOMParser * parser = new XercesDOMParser;
//parser->setToCreateXMLDeclTypeNode(false);
parser->setDoNamespaces(true);
parser->setCreateEntityReferenceNodes(true);
parser->setDoSchema(true);
// Create an input source
MemBufInputSource* memIS = new MemBufInputSource ((const XMLByte*)
txoh.buffer.rawBuffer(), txoh.offset, "XSECMem");
int errorCount = 0;
parser->parse(*memIS);
--SNIP--
+ some error and cleanup code
Cheers,
Berin
>
> From: "Dunko, Greg" <[EMAIL PROTECTED]>
> Subject: General usage questions
> Date: 24/01/2003 7:34:27
> To: "'[email protected]'" <[email protected]>
>
> Hiya folks. In the last couple days I've been trying to wrap my head around
> the Xalan/Xerces APIs and I've run into some trouble that I can't seem to
> get by.
>
> As background, I'm new to these APIs as the XML work I did a couple years
> ago was done using MSXML on Windows so I'm quite new to this library. I've
> tried looking at as much documentation and samples as I can but alas I have
> been unable to locate a clear direction for what I'm trying to do. The
> differences between the two libraries DOM models and the fact that the Xalan
> api uses the now deprecated Xerces DOM objects has me quite confused as to
> what I'm "supposed" to be doing to accomplish my task :)
>
> The basic issue is that I am trying to do some XSL transformations. My
> input is an XML string in memory, the stylesheet is in a file on disk, and
> I'd like my output to be in memory also (not in a file). I'd prefer DOM
> output instead of a string. It's not entirely clear to me on how to do
> this.
>
> My initial attempt was to use a std::stringstream object to construct an
> XSLTInputSource object but this didn't seem to work at all. Currently I
> have some code using the deprecated Xerces API to produce a DOM_Document.
> I'm then running that through the ParserLiasion and
> XercesDOMWrapperParsedSource objects to get it into the transform. This
> seems to work ok as long as the XSLTResultTarget points to a file on disk.
> My problem is that as soon as I try to make the output of the transformation
> use a XalanDocument it fails. I tried following what the documentation
> describes:
>
> XalanTransformer theXalanTransformer;
> XercesDOMSupport theDOMSupport;
> XercesParserLiaison theParserLiaison(theDOMSupport);
> // Produce input and stylesheet InputSources
> ....
> //
> XalanDocument* docOut = theParserLiaison.createDocument();
> XSLTResultTarget theDOMResultTarget(docOut);
> int theResult = theXalanTransformer.transform(parsedSource, stylesheet ,
> theDOMResultTarget);
>
> This seems to fail in the transform returning a -4. From inspecting the
> code this seems to be some sort of XercesException but there is no
> indication as to what the issue is. Remember that this works fine if
> theDOMResultTarget is constructed with a simple filename URI such as
> "output.xml". Just getting the DOM output doesn't seem to work for me.
> For a bit I thought the liaison could only be used once so I made a second
> one for making the XalanDocument but that didn't work either.
>
> Am I going about this whole thing the wrong way, making it more difficult
> than it needs to be? I would think this would be a fairly common task to
> perform and I'm a bit perplexed at the moment.
>
> Thanks for your help!
>
>
> --
> Greg Dunko
> Fidelity Investments
> 603.791.8216
> mailto:[EMAIL PROTECTED]
>
>
This message was sent through MyMail http://www.mymail.com.au