You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by um...@comcast.net on 2006/11/27 02:01:17 UTC

[Betwixt]: Error with a simple .betwixt file

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(org.apache.xerces.parsers.AbstractSAXParser$LocatorProxy@1c92535)
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 org.apache.commons.betwixt.digester.ElementRule@f1bb78
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org