Hi Dmitriy, you don't you use just the commons-digester rules to map the xml to your map? It's also a betwixt dependency library, and maybe it could be easier. Best regards, Simone
2008/9/1 Dmitriy Kuznetsov <[EMAIL PROTECTED]>: > > Hi. I am trying to load a map of <String, Object> from XML back to java using > betwixt - with no success. > I've exported a Hashtable of <String, Object> to XML using Betwixt 0.8. The > XML i've got is: > > <?xml version="1.0" encoding="UTF-8" ?> > <metadata> > <map> > <empty>true</empty> > <entry> > <key>gabbaGabbaHey</key> > <value>md-id-2</value> > </entry> > <entry> > <key>Entry1</key> > <value>123</value> > </entry> > <entry> > <key>halooppoRoste</key> > <value>-3.76</value> > </entry> > </map> > </metadata> > > After that, i am trying to load the XML back by the following code: > > BeanReader beanReader = new BeanReader(); > > > beanReader.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false); > beanReader.getBindingConfiguration().setMapIDs(false); > > try { > beanReader.registerBeanClass("map", Hashtable.class); > beanReader.registerBeanClass("entry/value", > String.class); > > Object tmp; > > File srcFile = new File("metadata.xml"); > tmp = instance.beanReader.parse(srcFile); > > } catch (Exception ex) { > logger.log(Level.SEVERE, "Failed to read metadata.", > ex); > return null; > } > > I played with beanReader.registerBeanClass - tried to set "metadata/map" and > "metadata/map/entry/value" as first parameter, disable registerBeanClass > commands, remove <metadata> tags from XML, but the only results i've got are > null in tmp variable, or EmptyStackException > > Sep 1, 2008 5:39:52 PM org.apache.commons.digester.Digester endElement > SEVERE: End event threw exception > java.util.EmptyStackException > at org.apache.commons.collections.ArrayStack.peek(ArrayStack.java:94) > at > org.apache.commons.betwixt.io.read.ReadContext.getBean(ReadContext.java:351) > at > org.apache.commons.betwixt.expression.CollectionUpdater.update(CollectionUpdater.java:47) > at > org.apache.commons.betwixt.io.read.BeanBindAction.update(BeanBindAction.java:171) > at > org.apache.commons.betwixt.io.read.BeanBindAction.end(BeanBindAction.java:158) > at > org.apache.commons.betwixt.io.BeanRuleSet$ActionMappingRule.end(BeanRuleSet.java:316) > at org.apache.commons.digester.Digester.endElement(Digester.java:1222) > at > com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown > Source) > at > com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown > Source) > at > com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown > Source) > at > com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown > Source) > at > com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown > Source) > at > com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown > Source) > at > com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown > Source) > at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown > Source) > at > com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown > Source) > at > com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown > Source) > at org.apache.commons.digester.Digester.parse(Digester.java:1728) > at > com.aleri.lms.ui.beans.XMLMetadataProvider.loadMetadata(XMLMetadataProvider.java:83) > at > com.aleri.lms.ui.beans.XMLMetadataProvider.main(XMLMetadataProvider.java:74) > java.util.EmptyStackException > at > org.apache.commons.digester.Digester.createSAXException(Digester.java:3181) > at > org.apache.commons.digester.Digester.createSAXException(Digester.java:3207) > at org.apache.commons.digester.Digester.endElement(Digester.java:1225) > at > com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.endElement(Unknown > Source) > at > com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanEndElement(Unknown > Source) > at > com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown > Source) > at > com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown > Source) > at > com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown > Source) > at > com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown > Source) > at > com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown > Source) > at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown > Source) > at > com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown > Source) > at > com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown > Source) > at org.apache.commons.digester.Digester.parse(Digester.java:1728) > at > com.aleri.lms.ui.beans.XMLMetadataProvider.loadMetadata(XMLMetadataProvider.java:83) > at > com.aleri.lms.ui.beans.XMLMetadataProvider.main(XMLMetadataProvider.java:74) > > Well, at the end of all i need an instance of Map<String, Object>. If i have > to anjust my XML file to accomplish this, it's ok. If there is a solution, > that allows to keep information about order of entries in XML file, i would > better implement it, instead of plain map. > Could you please explain me, how to do it? At least, how to load Map from > XML? > > I understand, that my question may be lame. But i am trying variants, > tracing code and looking for answer for about three days, and found nothing > that could help. I believe it would be perfect to have a sample or entry in > FAQ with working code that loads Map from XML. > -- > View this message in context: > http://www.nabble.com/Commons-betwixt-0.8---reading-Map-from-XML-tp19255879p19255879.html > Sent from the Commons - User mailing list archive at Nabble.com. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > -- My LinkedIn profile: http://www.linkedin.com/in/simonetripodi My GoogleCode profile: http://code.google.com/u/simone.tripodi/ My Sourceforge: https://sourceforge.net/users/stripodi My Picasa: http://picasaweb.google.com/simone.tripodi/ My Tube: http://www.youtube.com/user/stripodi My Del.icio.us: http://del.icio.us/simone.tripodi --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]