Skip to content
Advertisement

Java how to use XMLStreamReader and XMLStreamWriter in the same method

I use XMLStreamReader to read xml file. I want to copy this actual file and add somes nodes in this file :

JavaScript

When I try to run I have this error : Exception in thread "main" java.lang.ClassCastException: class com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl cannot be cast to class javax.xml.stream.XMLStreamWriter

What is the best way to do that ?

Advertisement

Answer

Use an XMLOutputFacotry instead to create the output stream

JavaScript

Note the use of another path for the output file

Advertisement