You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by Charlie Wu <da...@pacbell.net> on 2001/02/10 09:11:00 UTC
problem with xalan-j in servlets
Hi all:
I've tried to battle this weird problem for 3 days and still can't figure it out.. please help!!
Basically I'm trying to convert an XML string to an HTML string via an XSL file.. the program runs fine from the
command line.. but fails if I run it as a servlet.. I've tried weblogic, jrun and java web server. same error..
I have the latest of xerces.jar (1.3, size is 787419).. and xalan.jar (size 702536).. and I've made
sure I put xalan.jar and xerces.jar at the very first of the appserver's CLASSPATH.. what could
I be missing here???
Thanks all
Charlie
sample error log from jrun:
javax.xml.transform.TransformerConfigurationException: Namespace not supported by SAXParser
at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:650)
at mco.costanalysis.combat.XML2HTML.doProcess(XML2HTML.java:16)
at mco.costanalysis.combat.CBTSpendUsageAnal.doPost(CBTSpendUsageAnal.java:42)
at mco.costanalysis.combat.CBTSpendUsageAnal.doGet(CBTSpendUsageAnal.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
at allaire.jrun.servlet.JRunNamedDispatcher.forward(../servlet/JRunNamedDispatcher.java:34)
at allaire.jrun.servlet.Invoker.service(../servlet/Invoker.java:84)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:88)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1131)
at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:330)
at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:107)
at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)
Dom Input sample problem
Posted by mahesh <ma...@finessealliance.com>.
Hi
I compiled xalan c in solaris successfully. I was able to execute the samples given with source code.
I tried to use Dom Input to XSLT. I compiles and run well. but the output xml file I received is not correct, I could get the problem. Could you please tell me what is wrong.
The source code is
------------------------------------------------------------------------------
int
xsltMain(const CmdLineParams& params)
{
#if defined(XALAN_USE_ICU)
// Create an installer to install the substitue format-number() function.
FunctionICUFormatNumber::FunctionICUFormatNumberInstaller theInstaller;
// Create a factory for creating XalanNumberFormat instances using
// the ICU as implementation...
ICUXalanNumberFormatFactory theXalanNumberFormatFactory;
// Install the ICU-based factory...
StylesheetExecutionContextDefault::installXalanNumberFormatFactory(&theXalanNumberFormatFactory);
#endif
// Use the Xerces DOM parser to create a DOM_Document.
DOMParser theParser;
theParser.parse("sample1.xml");
const DOM_Document theDOM = theParser.getDocument();
// Set up a XercesParserLiaison and use it to wrap the DOM_Document
// in a XalanDocument.
DOMSupportDefault theDOMSupport;
XercesParserLiaison xmlParserLiaison(theDOMSupport);
XalanDocument* theDoc = xmlParserLiaison.createDocument(theDOM);
const XalanDOMString mimeEncoding(XALAN_STATIC_UCODE_STRING("UTF-8"));
const XalanDOMString encoding(XALAN_STATIC_UCODE_STRING("UTF-8"));
/**
* The default diagnostic writer...
*/
XalanStdOutputStream theStdErr(cerr);
XalanOutputStreamPrintWriter diagnosticsWriter(theStdErr);
XPathSupportDefault theXPathSupport(theDOMSupport);
XSLTProcessorEnvSupportDefault theXSLProcessorSupport;
#if defined(XALAN_USE_BLOCK_XOBJECT_FACTORY)
XObjectFactoryArena theBlockXObjectFactory;
XObjectFactoryDefault theXObjectFactoryDefault;
XObjectFactory& theXObjectFactory =
selectXObjectFactory(
theXObjectFactoryDefault,
theBlockXObjectFactory,
params.useBlockXObjectFactory);
#else
XObjectFactoryDefault theXObjectFactory;
#endif
XPathFactoryDefault theXPathFactory;
const XalanAutoPtr<TraceListener> theTraceListener(
createTraceListener(
params,
diagnosticsWriter));
XSLTEngineImpl processor(
xmlParserLiaison,
theXPathSupport,
theXSLProcessorSupport,
theDOMSupport,
theXObjectFactory,
theXPathFactory);
theXSLProcessorSupport.setProcessor(&processor);
if (theTraceListener.get() != 0)
{
processor.setTraceSelects(params.traceSelectionEvent);
processor.addTraceListener(theTraceListener.get());
}
// Use a separate factory instance for the stylesheet. This is really only necessary
// if you want to use the stylesheet with another processor, or you want to use
// it multiple times.
XPathFactoryDefault theStylesheetXPathFactory;
StylesheetConstructionContextDefault theConstructionContext(processor,
theXSLProcessorSupport,
theStylesheetXPathFactory);
/*
* Set specified processor flags
*/
processor.setQuietConflictWarnings(params.setQuietConflictWarnings);
if (params.paramsMap.size())
{
String2StringMapType::const_iterator it = params.paramsMap.begin();
for ( ; it != params.paramsMap.end(); ++it)
{
processor.setStylesheetParam(
c_str((*it).first),
c_str((*it).second));
}
}
/*
* Set specified parser flags
*/
if (params.indentAmount != 0)
{
xmlParserLiaison.setIndent(params.indentAmount);
}
xmlParserLiaison.setSpecialCharacters(c_str(params.specialCharacters));
xmlParserLiaison.SetShouldExpandEntityRefs(params.shouldExpandEntityRefs);
xmlParserLiaison.setUseValidation(params.doValidation);
assert(params.inFileName.size() > 0);
if (!params.setQuietMode)
{
processor.setDiagnosticsOutput(&diagnosticsWriter);
}
XalanDOMString xslFileName;
if(0 != params.xslFileName.size())
{
file://xslFileName = c_str(params.xslFileName);
strcpy(xslFileName,"sample1.xsl");
}
const StylesheetRoot* stylesheet = 0;
if (!isEmpty(xslFileName))
{
stylesheet = processor.processStylesheet(xslFileName, theConstructionContext);
}
XalanAutoPtr<XalanOutputStream> outputFileStream(createOutputStream(params));
assert(outputFileStream.get() != 0);
XalanOutputStreamPrintWriter resultWriter(*outputFileStream.get());
const XalanAutoPtr<FormatterListener> formatter(
createFormatter(
params.outputType,
params.shouldWriteXMLHeader,
params.stripCData,
params.escapeCData,
resultWriter,
xmlParserLiaison.getIndent(),
mimeEncoding,
stylesheet,
xmlParserLiaison));
XSLTResultTarget rTreeTarget;
if(formatter.get() == 0)
{
rTreeTarget.setCharacterStream(&resultWriter);
}
else
{
rTreeTarget.setFormatterListener(formatter.get());
}
// Do the transformation...
// Use the XalanDocument to create an XSLTInputSource object, which
// you can then use in a transformation.
XSLTInputSource theInputSource(theDoc);
StylesheetExecutionContextDefault theExecutionContext(processor,
theXSLProcessorSupport,
theXPathSupport,
theXObjectFactory);
#if defined(XALAN_USE_ICU)
ICUBridgeCollationCompareFunctor theICUFunctor;
theExecutionContext.installCollationCompareFunctor(&theICUFunctor);
#endif
if (stylesheet == 0)
{
// No stylesheet, so our only hope is that the xml file has
// PI with the stylesheet...
// Dummy input source...
XSLTInputSource theStylesheetSource;
processor.process(
theInputSource,
theStylesheetSource,
rTreeTarget,
theConstructionContext,
theExecutionContext);
}
else
{
theExecutionContext.setStylesheetRoot(stylesheet);
processor.process(
theInputSource,
rTreeTarget,
theExecutionContext);
}
if (params.outputType == FormatterListener::OUTPUT_METHOD_DOM)
{
// Output is to DOM, so we have to format to XML to
// produce output...
assert(rTreeTarget.getFormatterListener() != 0 &&
rTreeTarget.getFormatterListener()->getOutputFormat() ==
FormatterListener::OUTPUT_METHOD_DOM);
// Get the FormatterToDOM that produced the result document...
const FormatterToDOM* const theResultFormatter =
#if defined(XALAN_OLD_STYLE_CASTS)
(FormatterToDOM*)rTreeTarget.getFormatterListener();
#else
static_cast<FormatterToDOM*>(rTreeTarget.getFormatterListener());
#endif
// Get the document...
const XalanDocument* const theResultDocument =
theResultFormatter->getDocument();
if (theResultDocument == 0)
{
cerr << endl << "Warning: No DOM document to format!!!" << endl;
}
else
{
// Create a FormaterToDOM with the required output
// options...
const XalanAutoPtr<FormatterListener> formatter(
createFormatter(
FormatterListener::OUTPUT_METHOD_XML,
params.shouldWriteXMLHeader,
params.stripCData,
params.escapeCData,
resultWriter,
xmlParserLiaison.getIndent(),
mimeEncoding,
stylesheet,
xmlParserLiaison));
// Create a FormatterTreeWalker with the the
// new formatter...
FormatterTreeWalker theTreeWalker(*formatter.get());
// Walk the document and produce the XML...
theTreeWalker.traverse(theResultDocument);
}
}
#if !defined(NDEBUG)
if (params.showStats == true)
{
cerr << endl
#if !defined(XALAN_USE_BLOCK_XOBJECT_FACTORY)
<< "Execution XObject details:"
<< endl
<< endl
<< "Total number of XBoolean instances created: "
<< theXObjectFactory.getTotalBooleanInstanceCount()
<< endl
<< "Total number of XNodeSet instances created: "
<< theXObjectFactory.getTotalNodeSetInstanceCount()
<< endl
<< "Total number of XNull instances created: "
<< theXObjectFactory.getTotalNullInstanceCount()
<< endl
<< "Total number of XNumber instances created: "
<< theXObjectFactory.getTotalNumberInstanceCount()
<< endl
<< "Total number of XResultTreeFrag instances created: "
<< theXObjectFactory.getTotalResultTreeFragInstanceCount()
<< endl
<< "Total number of XString instances created: "
<< theXObjectFactory.getTotalStringInstanceCount()
<< endl
<< "Total number of XUnknown instances created: "
<< theXObjectFactory.getTotalUnknownInstanceCount()
<< endl
<< endl
#endif
<< "Execution XPath details:"
<< endl
<< endl
<< "Total number of XPath instances created: "
<< theXPathFactory.getTotalInstanceCount()
<< endl
<< endl
<< endl
<< "Stylesheet XPath details:"
<< endl
<< endl
<< "Total number of XPath instances created: "
<< theStylesheetXPathFactory.getTotalInstanceCount()
<< endl
<< endl;
}
#endif
theExecutionContext.reset();
theConstructionContext.reset();
theStylesheetXPathFactory.reset();
processor.reset();
theXPathFactory.reset();
theXObjectFactory.reset();
theXSLProcessorSupport.reset();
theXPathSupport.reset();
xmlParserLiaison.reset();
return 0;
}
------------------------------------------------------------------------------
Re: problem with xalan-j in servlets (update)
Posted by Charlie Wu <da...@pacbell.net>.
more error follows.. seems like xalan is trying to use com.sun.xml.parser.SAXParserImpl... how can I
get it to use xerces???
I'm attaching my java code ..
Thanks
Charlie
javax.xml.parsers.ParserConfigurationException: Namespace not supported by SAXParser
at com.sun.xml.parser.SAXParserImpl.<init>(SAXParserImpl.java:60)
at com.sun.xml.parser.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:57)
at org.apache.xalan.processor.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:761)
at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:635)
at mco.costanalysis.combat.XML2HTML.doProcess(XML2HTML.java:16)
at mco.costanalysis.combat.CBTSpendUsageAnal.doPost(CBTSpendUsageAnal.java:42)
at mco.costanalysis.combat.CBTSpendUsageAnal.doGet(CBTSpendUsageAnal.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
at allaire.jrun.servlet.JRunNamedDispatcher.forward(../servlet/JRunNamedDispatcher.java:34)
at allaire.jrun.servlet.Invoker.service(../servlet/Invoker.java:84)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:88)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1131)
at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:330)
at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:107)
at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)
----- Original Message -----
From: Charlie Wu
To: xalan-dev@xml.apache.org
Sent: Saturday, February 10, 2001 12:11 AM
Subject: problem with xalan-j in servlets
Hi all:
I've tried to battle this weird problem for 3 days and still can't figure it out.. please help!!
Basically I'm trying to convert an XML string to an HTML string via an XSL file.. the program runs fine from the
command line.. but fails if I run it as a servlet.. I've tried weblogic, jrun and java web server. same error..
I have the latest of xerces.jar (1.3, size is 787419).. and xalan.jar (size 702536).. and I've made
sure I put xalan.jar and xerces.jar at the very first of the appserver's CLASSPATH.. what could
I be missing here???
Thanks all
Charlie
sample error log from jrun:
javax.xml.transform.TransformerConfigurationException: Namespace not supported by SAXParser
at org.apache.xalan.processor.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:650)
at mco.costanalysis.combat.XML2HTML.doProcess(XML2HTML.java:16)
at mco.costanalysis.combat.CBTSpendUsageAnal.doPost(CBTSpendUsageAnal.java:42)
at mco.costanalysis.combat.CBTSpendUsageAnal.doGet(CBTSpendUsageAnal.java:27)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
at allaire.jrun.servlet.JRunNamedDispatcher.forward(../servlet/JRunNamedDispatcher.java:34)
at allaire.jrun.servlet.Invoker.service(../servlet/Invoker.java:84)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1013)
at allaire.jrun.servlet.JRunSE.runServlet(../servlet/JRunSE.java:925)
at allaire.jrun.servlet.JRunRequestDispatcher.forward(../servlet/JRunRequestDispatcher.java:88)
at allaire.jrun.servlet.JRunSE.service(../servlet/JRunSE.java:1131)
at allaire.jrun.servlet.JvmContext.dispatch(../servlet/JvmContext.java:330)
at allaire.jrun.http.WebEndpoint.run(../http/WebEndpoint.java:107)
at allaire.jrun.ThreadPool.run(../ThreadPool.java:272)
at allaire.jrun.WorkerThread.run(../WorkerThread.java:75)