Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error at line -1 when using SimpleXml to parse xml

When parsing my XML files with Simple, I get errors like the following one:

org.simpleframework.xml.core.ValueRequiredException: 
Unable to satisfy ... on field 'id' private String Foo.id 
for class Foo at line -1

What do I need to change to get the real line number?

[EDIT] Here is a Gist: Demo for SimpleXml line number problem

I'm using simple-xml:2.6.1 and junit:4.9

like image 951
Aaron Digulla Avatar asked Jan 22 '26 18:01

Aaron Digulla


1 Answers

Depends on where it is run. If you run in JDK 1.5, witout StAX in the classpath this means you are using DOM, so you will always get -1 on an error. If you use JDK 1.5 or above with StAX in the classpath then StAX does not support line numbers (perhaps try a different lib, I recomment Woodstox).

[EDIT] If you want to try Woodstox and you use Maven, add this to your POM:

<dependency>
    <groupId>org.codehaus.woodstox</groupId>
    <artifactId>woodstox-core-asl</artifactId>
    <version>4.1.2</version>
</dependency>
<dependency>
    <groupId>org.codehaus.woodstox</groupId>
    <artifactId>stax2-api</artifactId>
    <version>3.1.1</version>
</dependency>

This is the version which uses Apache License 2.0. If you prefer LGPL 2.1, replace -asl with -lgpl.

like image 96
ng. Avatar answered Jan 24 '26 08:01

ng.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!