Subjects
Home
Xalan extension functions
Fomatting question serializing DOM with pretty print
xalan with pull parser
Cannot find the declaration
Apache Xalan drop support to run on JRE 1 1 x
Why does Doctype change processing of a document
Node set to XML string via Java extensions in Xalan J: possible?
Templates/Transformers + thread safety???
Problem evaluating xpath with muliple prefix with different namespace
remove an arbitrary attribute from xsl output
Xalan3 XSLT 2 0 XPath 2 0 support?
Problem using compiled translets with Xalan !!
Xalan and jstl 1 1 problem with transform tag
NullPointer in DOM2DTM getLocalName
URIResolvers base parameter with xsltc and cascaded imports
Performance problem for Xalan J on intel dual core
Standard libraries in JAXP?
Serializing a DOM tree to XML file, customize entities replacement
Library Conflict Involving BCEL Library
A question on how users are using <xsl:message >
Kevin Cormier as a new Apache Xalan J committer
Struggling to iterate over tokenized string
Xalan count() trouble
Problem with recursive xpath
Error when switching to java 1 5
document( ' ')
Problem with Xalan2 7 0 transformation
cr/lf options
entity encoded XML
can xalan transform 2 xml using one xslt?
Xalan J JIRA defect review Monday October 16, 2006 from 2:00 to 3:30 pm ED
xsl transform with cdata section elements
xslt parameters not expanded
Weird behavior of XPath evaluate()
How to avoid <xsl:message > instruction prints stylesheet file informations ?
Cannot find SimpleTransform subdirectory after installing Xalan J
recover from document not found exceptions
jdk1 5 and Xalan jar differences?
Performance Issue
Error/Bug adding floating point numbers
XPathAPI: eval exp using nodes with default namespace
modifying xalan to output invalid XML
NullPointerException
mege two separate xml nodes into one
Is this a XALAN document identification bug?
is StylesheetRoot really java io Serializable ?
transform() fails for DOMSource but succeeds for StreamSource
Thoughts on Transformer parameter passing
HELP, Xalan and jstl 1 1 problem with transformer
Problem with XPath namespace axis?
string utils:replace deleting search string if replacement string is an HTML
help with enumeration values pls
xalan 2 5 1 vs 2 7 performance question
How to insert/update in XML document
HTML Serialization and Handling of Ampersands in HREF Attributes
XHTML link tag stripping
SystemId Unknown; Line #24; Column #49; java lang NullPointerException
xpath text() help
Apostrophe problem with xalan 2 7 0
How to set variables in XML document?
Links
Home
Oracle database error code ...
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Node-set to XML string via Java extensions in Xalan-J: possible?

Node-set to XML string via Java extensions in Xalan-J: possible?

2007-02-22       - By Kevin Cormier
Reply:     1     2     3     4     5     6     7  

Hi Mike,

The getDefaultMethodProperties(String method) method of the
org.apache.xml.serializer.OutputPropertiesFactory class is static, so you
can't call it on the instance that you've created.  You can call it like
this:

<xsl:variable name="formatprops"
select="java:org.apache.xml.serializer.OutputPropertiesFactory
.getDefaultMethodProperties('xml')"/>

As for the SerializerFactory, its constructor is private, so it can't be
instantiated directly.  You have to use the static getSerializer(Properties
format) method to obtain an instance.

Hope this helps.

Kevin Cormier
Software Developer, XSLT Development
IBM Toronto Lab, D1-435
Phone: 905-413-5771
E-mail:  kcormier@(protected)


                                                                         
            Mike Brown                                                    
            <mike@(protected)>                                              
                                                                       To
            02/22/2007 12:41          xalan-j-users@(protected)        
            PM                                                         cc
                                                                         
                                                                  Subject
                                      Node-set to XML string via Java    
                                      extensions in Xalan-J: possible?    
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         
                                                                         




I'm trying to serialize nodes to an XML string, using Java extensions. I'm
trying to avoid writing my own. I thought perhaps I could use the
DOMSerializer in Xalan-J.

However, I'm having trouble calling certain methods. They're documented as
existing, but Xalan-J is not finding them. For example, I can instantiate
an
OutputPropertiesFactory, but I can't call its getDefaultMethodProperties()
method. And I can't instantiate a SerializerFactory at all.



Here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<greetings>
 <greeting xml:lang="en">hello!</greeting>
 <greeting xml:lang="es">&#161;hola!</greeting>
 <greeting xml:lang="fr">bonjour!</greeting>
 <greeting
xml:lang="ru">&#1047;&#1076;&#1088;&#1072;&#1074;&#1089;&#1090;&#1074;&#1091;&
#1081;&#1090;&#1077;!</greeting>

 <greeting xml:lang="ja">&#20170;&#26085;&#12399;</greeting>
</greetings>


Here is my XSLT (the failure is when I try to create $formatprops):

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:java="http://xml.apache.org/xalan/java">

 <xsl:output method="text" indent="no"/>

 <xsl:template match="/">
   <xsl:variable name="nodeset" select="/greetings"/>
   <!--OutputPropertiesFactory opropsfactory = new
OutputPropertiesFactory();-->
   <xsl:variable name="opropsfactory"
select="java:org.apache.xml.serializer.OutputPropertiesFactory.new()"/>
   <!--String method = org.apache.xml.serializer.Method.XML;
Properties formatprops =
opropsfactory.getDefaultMethodProperties(method);-->
   <xsl:variable name="formatprops"
select="java:getDefaultMethodProperties($opropsfactory, 'xml')"/>
   <!--SerializerFactory serializerfactory = new SerializerFactory();-->
   <xsl:variable name="serializerfactory"
select="java:org.apache.xml.serializer.SerializerFactory.new()"/>
            <!--Serializer serializer =
serializerfactory.getSerializer(formatprops);-->
            <xsl:variable name="serializer"
select="java:getSerializer($serializerfactory, $formatprops)"/>
            <!--StringWriter buffer = new StringWriter();-->
            <xsl:variable name="buffer"
select="java:java.io.StringWriter.new()"/>
            <!--serializer.setWriter(buffer);-->
            <xsl:variable name="void1" select="java:setWriter($serializer,
$buffer)"/>
            <!--DOMSerializer domserializer =
serializer.asDOMSerializer();-->
            <xsl:variable name="domserializer"
select="java:asDOMSerializer($serializer)"/>
            <!--domserializer.serialize(node);-->
            <xsl:variable name="void2"
select="java:serialize($domserializer, $nodeset)"/>
            <!--System.out.write(buffer.toString());-->
            <xsl:value-of select="java:toString($buffer)"/>
 </xsl:template>

</xsl:stylesheet>


Here is how I am invoking Xalan-J, and the error message:

C:\dev\test>java -Djava.endorsed.dirs=C:\dev\xalan-j_2_7_0 -cp
C:\dev\xalan-j_2_7_0\xalan.jar;C:\dev\xalan-j_2_7_0\serializer.jar
org.apache.xalan.xslt.Process -IN greetings.xml -XSL xalanserialize.xsl
-EDUMP

; SystemID: file:///C:/dev/test/xalanserialize.xsl; Line#: 14; Column#: 103
javax.xml.transform.TransformerException: java.lang.NoSuchMethodException:
For extension function, could not find method
org.apache.xml.serializer.OutputPropertiesFactory.getDefaultMethodProperties(
[ExpressionContext,]
#STRING).
       at
org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction
(ExtensionHandlerJavaPackage.java:420)

       at
org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction
(ExtensionHandlerJavaPackage.java:438)

       at
org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java
:220)

       at
org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java
:473)

       at
org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:206)

       at org.apache.xpath.XPath.execute(XPath.java:335)
       at
org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:278)
       at
org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:246)
       at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2411)

       at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode
(TransformerImpl.java:2281)

       at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java
:1367)

       at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)

       at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java
:1284)

       at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java
:1262)

       at org.apache.xalan.xslt.Process.main(Process.java:1046)
---------
java.lang.NoSuchMethodException: For extension function, could not find
method
org.apache.xml.serializer.OutputPropertiesFactory.getDefaultMethodProperties(
[ExpressionContext,]
#STRING).
       at
org.apache.xalan.extensions.MethodResolver.getMethod(MethodResolver.java:274)

       at
org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction
(ExtensionHandlerJavaPackage.java:381)

       at
org.apache.xalan.extensions.ExtensionHandlerJavaPackage.callFunction
(ExtensionHandlerJavaPackage.java:438)

       at
org.apache.xalan.extensions.ExtensionsTable.extFunction(ExtensionsTable.java
:220)

       at
org.apache.xalan.transformer.TransformerImpl.extFunction(TransformerImpl.java
:473)

       at
org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:206)

       at org.apache.xpath.XPath.execute(XPath.java:335)
       at
org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:278)
       at
org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:246)
       at
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates
(TransformerImpl.java:2411)

       at
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode
(TransformerImpl.java:2281)

       at
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java
:1367)

       at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:709)

       at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java
:1284)

       at
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java
:1262)

       at org.apache.xalan.xslt.Process.main(Process.java:1046)
Exception in thread "main" java.lang.RuntimeException:
java.lang.NoSuchMethodException: For extension function, could not find
method
org.apache.xml.serializer.OutputPropertiesFactory.getDefaultMethodProperties(
[ExpressionContext,]
#STRING).
       at org.apache.xalan.xslt.Process.doExit(Process.java:1153)
       at org.apache.xalan.xslt.Process.main(Process.java:1126)


If I try to create the SerializerFactory first, I get a similar error about
its constructor
not being found. Am I doing something wrong?

Thanks,
Mike