users@jaxb.java.net

Re: New to JAXB -- having problems

From: Hanasaki JiJi <hanasaki_at_hanaden.com>
Date: Mon, 10 Mar 2003 16:10:21 -0600

Write a short test program that builds an instance and mashalls it out.
  Then edit from there. hand-writting xml files this detailed is like
writting assembler in hex instead of phonemics.

be very careful! you MUST use the objectfactory to get new instances of
nodes and all MUST be fully filled it.

Canning, Chuck wrote:
> Hi,
>
> I am new to JAXB and to XML schema. Theschema that I have generates code,
> but I am having troublke parsing XML files against the schema. Here is my
> schema:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>
> <!--**********************************************************************
> * The event system configuration instance.
>
> **********************************************************************-->
> <xsd:element name="Config" type="EventSystemConfiguration">
> </xsd:element>
>
> <!--**********************************************************************
> * The event system configuration.
>
> **********************************************************************-->
> <xsd:complexType name="EventSystemConfiguration">
> <xsd:complexContent>
> <xsd:extension base="Configuration">
> <xsd:sequence>
> <xsd:element name="Channels" type="xsd:string">
> </xsd:element>
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <!--**********************************************************************
> * The collection of channels.
>
> **********************************************************************-->
> <xsd:complexType name="Channels">
> <xsd:sequence>
> <xsd:element name="ChannelList" type="Channel" minOccurs="0"
> maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <!--**********************************************************************
> * The channel.
>
> **********************************************************************-->
> <xsd:complexType name="Channel">
> <xsd:sequence>
> <xsd:element name="Dispatcher" type="TopicDispatcher"/>
> </xsd:sequence>
> <xsd:attribute name="ID" type="channelID" use="required"/>
> </xsd:complexType>
>
> <!--**********************************************************************
> * The Topic dispatcher.
>
> **********************************************************************-->
> <xsd:complexType name="TopicDispatcher">
> <xsd:complexContent>
> <xsd:extension base="Dispatcher">
> <xsd:sequence>
> <xsd:element name="FactoryName" type="xsd:string"/>
> <xsd:element name="TopicName" type="xsd:string"/>
> </xsd:sequence>
> </xsd:extension>
> </xsd:complexContent>
> </xsd:complexType>
>
> <!--**********************************************************************
> * The supported channel ID enumeration.
>
> **********************************************************************-->
> <xsd:simpleType name="channelID">
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="Engine"/>
> <xsd:enumeration value="Management"/>
> <xsd:enumeration value="Modeling"/>
> </xsd:restriction>
> </xsd:simpleType>
>
> <!--**********************************************************************
> * The dispatcher base type.
>
> **********************************************************************-->
> <xsd:complexType name="Dispatcher">
> <xsd:sequence>
> <xsd:element name="ClassName" type="xsd:string"/>
> </xsd:sequence>
> </xsd:complexType>
>
> <!--**********************************************************************
> * The configuration base type.
>
> **********************************************************************-->
> <xsd:complexType name="Configuration">
> </xsd:complexType>
> </xsd:schema>
>
> Here is a sample xml file
>
> <?xml version="1.0"?>
> <Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="./config.xsd">
>
> <Channels>
> <ChannelList ID="Modeling">
> <Dispatcher>
> <ClassName>JMSTopicDispatcher</ClassName>
> <FactoryName>Connectionfactory</FactoryName>
> <TopicName>jms/Modeling</TopicName>
> </Dispatcher>
> </Channel>
> </Channels>
> </Config>
>
> When I try to unmarshall this file, it complains about the ChannelList is an
> unexpected element. I have tried stepping through the code and in the method
>
>
> public void enterElement(String ___uri, String ___local,
> org.xml.sax.Attributes __atts)
> throws com.sun.xml.bind.unmarshaller.UnreportedException
> {
> System.out.println("Local: " + ___local);
> System.out.println("State: " + state);
> switch (state) {
> case 0 :
> if ("".equals(___uri)&&"Channels".equals(___local)) {
> spawnSuperClassFromEnterElement((new
> impl.ConfigurationImpl.Unmarshaller(context)), 1, ___uri, ___local, __atts);
> return ;
> }
> break;
> case 1 :
> if ("".equals(___uri)&&"Channels".equals(___local)) {
> context.pushAttributes(__atts);
> state = 2;
> return ;
> }
> break;
> case 4 :
> revertToParentFromEnterElement(___uri, ___local,
> __atts);
> return ;
> }
> super.enterElement(___uri, ___local, __atts);
> }
>
> it sets the state to 2 from 1 and then it throws the exception immediately
> after as it re-enters this method and there is no state 2 defined. Is the
> code being generated correct for my schema or is there something wrong in
> the schema. Thnaks for any help you can provide. Thanks.
>
> Chuck

--
=================================================================
= Management is doing things right; leadership is doing the     =
=       right things.    - Peter Drucker                        =
=_______________________________________________________________=
=     http://www.sun.com/service/sunps/jdc/javacenter.pdf       =
=  www.sun.com | www.javasoft.com | http://wwws.sun.com/sunone  =
=================================================================