Skip to content
Advertisement

Tag: stax

Understanding XMLStreamReader and START_ELEMENT

Consider the following XML file: Why am I not getting a START_ELEMENT event when using XMLStreamReader. Code is (lifted from): Output on my side: Ref: Answer Turns out the documentation has it described: An XMLStreamReader instance is created with an initial event type START_DOCUMENT. So code should instead be: The loop is easier to write using XMLEventReader:

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 : 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 ? Answer Use an XMLOutputFacotry instead to

Advertisement