ws-jaxme-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t..@nitwit.de
Subject Re: unmarshalling exception
Date Thu, 27 May 2004 16:14:46 GMT
On Thursday 27 May 2004 13:07, Jochen Wiedmann wrote:
> Please be so kind and post a complete example with schema and example file.
> We also ought to know what version you are using. You may also file a bug
> report in Jira.

The following validates using 
http://apps.gotdotnet.com/xmltools/xsdvalidator/Default.aspx

<f4t-config xmlns="http://ws.apache.org/jaxme/examples/misc/address">
  <database>
    <jndi-url>jnp://foo</jndi-url>
    <fetch-size>100</fetch-size>
    <query id="idee"/>
    <query id="idee">blah</query>
  </database>
</f4t-config>

----------

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
	xmlns="http://ws.apache.org/jaxme/examples/misc/address" 
	targetNamespace="http://ws.apache.org/jaxme/examples/misc/address" >
	<xs:element name="database">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="jndi-url" minOccurs="1" maxOccurs="1" />
				<xs:element ref="fetch-size" minOccurs="1" maxOccurs="1" />
				<xs:element ref="query" minOccurs="1" maxOccurs="unbounded" />
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="f4t-config">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="database" minOccurs="1" maxOccurs="1" />
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="fetch-size" type="xs:int" />
	<xs:element name="jndi-url" type="xs:string" />
	<xs:element name="query">
		<xs:complexType>
			<xs:simpleContent>
				<xs:extension base="xs:string">
					<xs:attribute name="id" type="xs:string" />
				</xs:extension>
			</xs:simpleContent>
		</xs:complexType>
	</xs:element>
</xs:schema>



And this happens when unmarshalling:

Exception in thread "main" javax.xml.bind.UnmarshalException
	at 
org.apache.ws.jaxme.impl.JMUnmarshallerImpl.unmarshal(JMUnmarshallerImpl.java:103)
	at tests.jaxme.F4tPrinter.getXML(F4tPrinter.java:25)
	at tests.jaxme.F4tPrinter.main(F4tPrinter.java:42)
Caused by:
org.xml.sax.SAXParseException: Unexpected non-whitespace characters: 'blah'
	at 
org.apache.ws.jaxme.impl.JMHandlerBase.validationEvent(JMHandlerBase.java:119)
	at org.apache.ws.jaxme.impl.JMHandlerImpl.characters(JMHandlerImpl.java:65)
	at 
org.apache.ws.jaxme.examples.misc.address.impl.F4tConfigTypeHandler$DatabaseTypeHandler.characters(F4tConfigTypeHandler.java:198)
	at 
org.apache.ws.jaxme.examples.misc.address.impl.F4tConfigTypeHandler.characters(F4tConfigTypeHandler.java:330)
	at 
org.apache.ws.jaxme.impl.JMUnmarshallerHandlerImpl.characters(JMUnmarshallerHandlerImpl.java:146)
	at org.apache.xerces.parsers.AbstractSAXParser.characters(Unknown Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanContent(Unknown 
Source)
	at 
org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown

Source)
	at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown 
Source)
	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
	at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
	at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
	at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
	at 
org.apache.ws.jaxme.impl.JMUnmarshallerImpl.unmarshal(JMUnmarshallerImpl.java:98)
	at tests.jaxme.F4tPrinter.getXML(F4tPrinter.java:25)
	at tests.jaxme.F4tPrinter.main(F4tPrinter.java:42)

----------

import java.io.File;
import java.io.FileInputStream;
import java.io.StringWriter;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

import org.apache.ws.jaxme.examples.misc.address.F4tConfig;
import org.xml.sax.InputSource;

public class F4tPrinter
{
	public static F4tConfig getXML( InputSource pSource ) throws JAXBException
	{
		JAXBContext context = 
JAXBContext.newInstance( "org.apache.ws.jaxme.examples.misc.address" );
		Unmarshaller unmarshaller = context.createUnmarshaller();
		unmarshaller.setValidating(true);
		return (F4tConfig)unmarshaller.unmarshal( pSource );
	}

	public static String getAsString( F4tConfig pAddress ) throws JAXBException
	{
		StringWriter sw = new StringWriter();
		JAXBContext context = 
JAXBContext.newInstance( "org.apache.ws.jaxme.examples.misc.address" );
		Marshaller marshaller = context.createMarshaller();
		marshaller.marshal( pAddress, sw );
		return sw.toString();
	}

	public static void main( String[] args ) throws Exception
	{
		File f = new File( "f4t-config.xml" );
		InputSource isource = new InputSource( new FileInputStream( f ) );
		isource.setSystemId( f.toURL().toString() );
		F4tConfig addr = getXML( isource );

		// A simpler variant might be:
		// Address addr = unmarshaller.unmarshal(f);

		System.out.println( "XML:" );
		System.out.println( getAsString( addr ) );
	}
}

----------

The problem is the query tag which is supposed to have text (the query) and an 
attribute (id). I must admit that I'm a bloody schema newbie so it may be a 
fault on my side....

---------------------------------------------------------------------
To unsubscribe, e-mail: jaxme-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: jaxme-dev-help@ws.apache.org


Mime
View raw message