FasterXML / woodstox

The gold standard Stax XML API implementation. Now at Github.
Apache License 2.0
220 stars 81 forks source link

XMLEvent.asCharacters() throws a cast error on Kotlin #166

Closed Kryomancer closed 1 year ago

Kryomancer commented 1 year ago

I'm trying to make use of the library on Kotlin, but I cannot call asCharacters() on the events it returns. A tutorial I've followed suggests doing this to get the contents of a tag. My full code is here, the call ot asCharacters on line 36 is the first part where this fails.

The problematic part is:

var someString = nextEvent.asCharacters().data

which throws

Exception in thread "main" java.lang.ClassCastException: com.ctc.wstx.evt.CompactStartElement cannot be cast to javax.xml.stream.events.Characters
    at org.codehaus.stax2.ri.evt.BaseEventImpl.asCharacters(BaseEventImpl.java:47)

Calling isCharacters on the event returns false, but I'm 100% certain all elements this gets called on do contain a value within them. How do I access this value?

Kryomancer commented 1 year ago

My problem was that the tutorial was wrong and doesn't show that you need to get the next event after the starting tag.

cowtowncoder commented 1 year ago

@Kryomancer ok thank you for adding update & great things work now.