Castor is not marshalling/unmarshalling a Enumeration for me

Discussion in 'XML' started by PPA, Feb 13, 2007.

  1. PPA

    PPA Guest

    Hi Guys

    I am really new to XML/XSD and Castor. Could you please help me out
    here?

    I have following XSD:
    -----------------------------XSD
    STARTS-----------------------------------
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:simpleType name="valueType">
    <xs:restriction base="xs:string">
    <xs:enumeration value="string"/>
    <xs:enumeration value="boolean"/>
    </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="param">
    <xs:attribute name="name" use="required" type="xs:string"></
    xs:attribute>
    <xs:attribute name="value" use="required" type="xs:string"></
    xs:attribute>
    <xs:attribute name="type" use="required" type="valueType"></
    xs:attribute>
    </xs:complexType>
    </xs:schema>
    ------------------------------XSD
    ENDS----------------------------------
    I have generated the Java class against this xsd and the class Param
    has following attributes

    private java.lang.String _name;

    private java.lang.String _value;

    private com.test.types.ValueType _type;

    Now, just to test I created the the java object Param, populate it
    with name, value and type and then MARSHALL'ed it. The generated XML
    does not have <type> tag at all.

    Similarly if I create an XML with all three tags, and then unmarshall
    it, for Param object, type is coming out to be NULL.

    What is that I am missing? Please help.

    Regards,
    -PPA
     
    PPA, Feb 13, 2007
    #1
    1. Advertising

  2. > <xs:attribute name="type" use="required" type="valueType"></
    ....
    > Now, just to test I created the the java object Param, populate it
    > with name, value and type and then MARSHALL'ed it. The generated XML
    > does not have <type> tag at all.


    As others keep saying: Don't think in terms of tags; it just messes you
    up. Think in terms of elements and attributes. This avoids the confusion
    you've just displayed over what "tag" means.

    According to your schema, type is defined as an attribute of the param
    element. So what you should be seeing is

    <param name="something" value="something else" type="whatever"/>



    --
    () ASCII Ribbon Campaign | Joe Kesselman
    /\ Stamp out HTML e-mail! | System architexture and kinetic poetry
     
    Joe Kesselman, Feb 13, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris
    Replies:
    0
    Views:
    404
    Chris
    Feb 26, 2004
  2. Timo Nentwig

    JAXB unmarshalling problem

    Timo Nentwig, May 26, 2004, in forum: Java
    Replies:
    0
    Views:
    477
    Timo Nentwig
    May 26, 2004
  3. Sam Hwang
    Replies:
    0
    Views:
    626
    Sam Hwang
    Apr 26, 2005
  4. Chris
    Replies:
    0
    Views:
    452
    Chris
    Feb 26, 2004
  5. puvit82
    Replies:
    4
    Views:
    768
    puvit82
    Feb 1, 2008
Loading...

Share This Page