https://kotlinlang.org logo
#getting-started
Title
# getting-started
k

Kaj Koivunen

02/28/2023, 11:20 AM
I'm having trouble parsing XML using Woodstox on kotlin, I'm following a java tutorial ( https://www.baeldung.com/java-stax ) that otherwise seems to work but trying to read the actual values inside XML tags like:
Copy code
val something = nextEvent.asCharacters().data
fails with an exception:
Exception in thread "main" java.lang.ClassCastException: com.ctc.wstx.evt.CompactStartElement cannot be cast to javax.xml.stream.events.Characters
If I check the even with isCharacters it returns false even though it most definitely contains a value. How do I get that value?
k

kqr

02/28/2023, 1:17 PM
not sure how is this kotlin related. but I assume you are still in startElement and not in "body" element
k

Kaj Koivunen

02/28/2023, 1:33 PM
thanks, that works, I didn't expect the tutorial to be wrong