JAXP Document to String needed

I

iksrazal

I'm getting this error from Xerces - and I can't seem to get the right
xerces jar in place to fix it:

java.lang.NoSuchMethodError:
org.apache.xerces.util.NamespaceSupport.reset(Lorg/apache/xerces/util/SymbolTable;

My code - which some upgarde seemed to have broken:

public static final String getXml(Document document) throws
XMLHelperException
{
try
{
OutputFormat format = new OutputFormat(document);
StringWriter stringOut = new StringWriter();
XMLSerializer serial = new XMLSerializer( stringOut, format );
serial.asDOMSerializer();
serial.serialize(document.getDocumentElement());
return stringOut.toString();
}
catch(Exception e)
{
throw new XMLHelperException("XML Document to String Err", e);
}
}

Is there a JAXP - or some standard way - to do this?

iksrazal
 
C

Chris Smith

iksrazal said:
I'm getting this error from Xerces - and I can't seem to get the right
xerces jar in place to fix it:

java.lang.NoSuchMethodError:
org.apache.xerces.util.NamespaceSupport.reset(Lorg/apache/xerces/util/SymbolTable;

Your code doesn't call NamespaceSupport.reset... so you'll need to post
the entire stack trace, so we can figure out where your code is really
failing.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
I

iksrazal

Chris Smith said:
Your code doesn't call NamespaceSupport.reset... so you'll need to post
the entire stack trace, so we can figure out where your code is really
failing.

Thanks for the reply. Here's what I think is relevant - please let me
know if not.

----- Root Cause -----
java.lang.NoSuchMethodError:
org.apache.xerces.util.NamespaceSupport.reset(Lorg/apache/xerces/util/SymbolTable;)V
at org.apache.xml.serialize.XMLSerializer.reset(XMLSerializer.java:1424)
at org.apache.xml.serialize.BaseMarkupSerializer.setOutputCharStream(BaseMarkupSerializer.java:335)
at org.apache.xml.serialize.XMLSerializer.<init>(XMLSerializer.java:199)
at com.infoseg.mr.security.XMLHelper.getXml(XMLHelper.java:162)

Here's the same code with line numbers:

156 public static final String getXml(Document document) throws
XMLHelperException
157 {
158 try
159 {
160 OutputFormat format = new OutputFormat(document);
161 StringWriter stringOut = new StringWriter();
162 XMLSerializer serial = new XMLSerializer( stringOut,
format );
163 serial.asDOMSerializer();
164 serial.serialize(document.getDocumentElement());
165 return stringOut.toString();
166 }
167 catch(Exception e)
168 {
169 throw new XMLHelperException("XML Document to String
Err", e);
170 }
171 }

The way I read the stacktrace is the first line with my code is 162
above.

I was able to fix the problem with JAXP code - although I'd like to
fix this using xerces if possible.

public static final String getXml(Document document) throws
XMLHelperException
{
try
{
// Create source and result objects
Source source = new DOMSource(document);
StringWriter out = new StringWriter();
Result result = new StreamResult(out);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer();
transformer.transform(source, result);
return out.toString();
}
}

iksrazal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top