Hello...
Environment: JDK 1.5_02
Betwixt: 0.7
Pl help with any suggestions as this seemingly simple problem is
driving me nuts. I have a very simple .betwixt file as shown below:
<?xml version="1.0" encoding="UTF-8" ?>
<info primitiveTypes="attribute">
<element name="Foo">
<addDefaults/>
</element>
</info>
I attempt to write a an instance of Foo, and register the property mapping as
follows:
final String M = "... the XML fragment shown above...";
FileWriter outputWriter = ... ;
// Betwixt just writes out the bean as a fragment
// So if we want well-formed xml, we need to add the
prolog
outputWriter.write("<?xml version='1.0' ?>\n");
// Create a BeanWriter which writes to our prepared
stream
BeanWriter beanWriter = new BeanWriter(outputWriter);
// Configure betwixt
beanWriter.getXMLIntrospector().register(new
InputSource(new StringReader(M)));
beanWriter.getXMLIntrospector().getConfiguration().setAttributesForPrimitives(false);
beanWriter.getBindingConfiguration().setMapIDs(false);
beanWriter.enablePrettyPrint();
// If the base element is not passed in, Betwixt will
guess
// But let's write example bean as base element
'license'
beanWriter.write("Foo", Foo);
Betwixt throws an exception flagging
an ill formed betwixt file ("Invalid use of <element>. It should be nested
inside <info> or other
<element> nodes") as shown below:
// Logs:
0 [main] DEBUG org.apache.commons.digester.Digester.sax -
setDocumentLocator([EMAIL PROTECTED])
0 [main] DEBUG org.apache.commons.digester.Digester.sax - startDocument()
10 [main] DEBUG org.apache.commons.digester.Digester.sax -
startElement(,,info)
10 [main] DEBUG org.apache.commons.digester.Digester - Pushing body text ''
10 [main] DEBUG org.apache.commons.digester.Digester - New match='info'
10 [main] DEBUG org.apache.commons.digester.Digester - No rules found
matching 'info'.
10 [main] DEBUG org.apache.commons.digester.Digester.sax - characters(
)
10 [main] DEBUG org.apache.commons.digester.Digester.sax -
startElement(,,element)
10 [main] DEBUG org.apache.commons.digester.Digester - Pushing body text '
'
10 [main] DEBUG org.apache.commons.digester.Digester - New
match='info/element'
10 [main] DEBUG org.apache.commons.digester.Digester - Fire begin() for
[EMAIL PROTECTED]
10 [main] DEBUG org.apache.commons.betwixt.digester.ElementRule - (BEGIN)
name=license uri=null property=null type=null
10 [main] DEBUG org.apache.commons.betwixt.digester.MappedPropertyRule -
Cannot find property type.
10 [main] DEBUG org.apache.commons.betwixt.digester.MappedPropertyRule -
className=null base=null name=null
40 [main] DEBUG org.apache.commons.betwixt.digester.ElementRule - 'class'
attribute=null
40 [main] WARN org.apache.commons.digester.Digester - Empty stack
(returning null)
40 [main] ERROR org.apache.commons.digester.Digester - Begin event threw
exception
org.xml.sax.SAXException: Invalid use of <element>. It should be nested inside
<info> or other <element> nodes
at
org.apache.commons.betwixt.digester.ElementRule.begin(ElementRule.java:165)
at org.apache.commons.digester.Digester.startElement(Digester.java:1361)
/U
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]