JAXP Document to String needed

Discussion in 'Java' started by iksrazal, May 20, 2004.

  1. iksrazal

    iksrazal Guest

    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
    iksrazal, May 20, 2004
    #1
    1. Advertising

  2. iksrazal

    Chris Smith Guest

    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
    Chris Smith, May 20, 2004
    #2
    1. Advertising

  3. iksrazal

    iksrazal Guest

    Chris Smith <> wrote in message news:<4.net>...
    > 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/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
    iksrazal, May 21, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Willian Irving Zumwalt

    Re: JAXP code fragment help

    Willian Irving Zumwalt, Aug 25, 2003, in forum: Java
    Replies:
    2
    Views:
    360
    Roedy Green
    Aug 25, 2003
  2. Roger Varley

    How to use JAXP

    Roger Varley, Aug 29, 2003, in forum: Java
    Replies:
    0
    Views:
    401
    Roger Varley
    Aug 29, 2003
  3. Tobi Krausl
    Replies:
    0
    Views:
    628
    Tobi Krausl
    Nov 20, 2003
  4. Michael
    Replies:
    1
    Views:
    5,326
    Michael Berg
    Feb 22, 2004
  5. Piet71
    Replies:
    1
    Views:
    490
    Joe Kesselman
    Mar 7, 2007
Loading...

Share This Page