I've used Groovy 1.0 until now to parsing and changing some simple xml files. Now I've tried to switch to Groovy 1.5.4 and xml parsing is not working anymore:
Here's a xml snippet:
<?xml version="1.0"?>
<measurement>
<header>
<reader serialnumber="1023900611220"/>
<efficiencyBlockNumber>1</efficiencyBlockNumber>
</header>
...
</measurement>
<!-- some commet -->
and a groovy snippet:
private String rebuildEfbFile(String content) {
def root = new XmlSlurper().parseText(content.trim());
root.measurement.header.reader.@serialnumber = this.serialNumber
def pkg = root."package";
String dateStr = pkg.@date;
pkg.@date = rebuildDataDate(dateStr);
def efb = pkg.efficiencyBlockList.efficiencyBlock
dateStr = efb.@date;
efb.@date = rebuildDataDate(dateStr);
....
}
I want to change the value of the attribute "serialnumber" and return the changed xml to the caller. But now I'm getting only execptions like this:
groovy.lang.MissingFieldException: No such field: serialnumber for class: groovy.util.slurpersupport.NodeChildren
at groovy.lang.MetaClassImpl.setAttribute(MetaClassImpl.java:2096)
at groovy.lang.MetaClassImpl.setAttribute(MetaClassImpl.java:2590)
at org.codehaus.groovy.runtime.InvokerHelper.setAttribute(InvokerHelper.java:163)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setField(ScriptBytecodeAdapter.java:346)
at DataSender.rebuildEfbFile(DataSender.groovy:152) <-- here the exception happens
at DataSender.this$2$rebuildEfbFile(DataSender.groovy)
at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:226)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:899)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:77)
at DataSender.run(DataSender.groovy:100)
at java.lang.Thread.run(Thread.java:619)
So what I'm doing wrong. As I said the code is working fine in version 1.0
Thanks, Lothar
_____________________________________________________________________
Unbegrenzter Speicherplatz für Ihr E-Mail Postfach? Jetzt aktivieren!
http://www.digitaledienste.web.de/freemail/club/lp/?lp=7
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
Lothar
--
View this message in context: http://www.nabble.com/trouble-parsing-xml-in-Groovy-1.5.4-tp15565242p15609113.html
Sent from the groovy - user mailing list archive at Nabble.com.
I think a regression has crept in rather than an intended change.
It needs more investigation as I don't believe any unit tests
related to this have changed - though I haven't checked yet that
we have complete coverage in this area.
Paul.