Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > JAXP Document to String needed

Reply
Thread Tools

JAXP Document to String needed

 
 
iksrazal
Guest
Posts: n/a
 
      05-20-2004
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
 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      05-20-2004
iksrazal wrote:
> 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
 
Reply With Quote
 
 
 
 
iksrazal
Guest
Posts: n/a
 
      05-21-2004
Chris Smith <> wrote in message news:<>...
> iksrazal wrote:
> > 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.


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/SymbolTableV
at org.apache.xml.serialize.XMLSerializer.reset(XMLSe rializer.java:1424)
at org.apache.xml.serialize.BaseMarkupSerializer.setO utputCharStream(BaseMarkupSerializer.java:335)
at org.apache.xml.serialize.XMLSerializer.<init>(XMLS erializer.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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java 5/JAXP/ setParameter avoid conversion to string Piet71 XML 1 03-07-2007 12:57 AM
Serializing XML with JAXP - help needed Michael Java 1 02-22-2004 06:07 PM
Does JAXP/XSLT support schema validation Sony Antony Java 1 11-20-2003 02:33 PM
How to use JAXP Roger Varley Java 0 08-29-2003 02:23 PM
Re: JAXP code fragment help Willian Irving Zumwalt Java 2 08-25-2003 10:05 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57