Castor is not marshalling/unmarshalling a Enumeration for me

P

PPA

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
 
J

Joe Kesselman

said:
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"/>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top