I have a problem with the XJC tool that it doesn't generate an Enum class for the attribute myEnum using this schema.
<xs:element name="myClass">
<xs:complexType>
<xs:attribute name="myEnum" >
<xs:simpleType >
<xs:restriction base="xs:string">
<xs:maxLength value="1"/>
<xs:enumeration value="C"/>
<xs:enumeration value="M"/>
<xs:enumeration value="S"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
but it generates it if I use only this
<xs:simpleType >
<xs:restriction base="xs:string">
<xs:maxLength value="1"/>
<xs:enumeration value="C"/>
<xs:enumeration value="M"/>
<xs:enumeration value="S"/>
</xs:restriction>
</xs:simpleType>
here is the external binding file content :
<?xml version="1.0" encoding="UTF-8" ?>
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
version="2.1" xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<globalBindings typesafeEnumMemberName="generateName">
</globalBindings>
</bindings>
You could try this: define a small XSD file with just that particular type declared as a global type, e.g.:
<xs:simpleType name="myEnumSimpleType">
<xs:restriction base="xs:string">
<xs:maxLength value="1"/>
<xs:enumeration value="C"/>
<xs:enumeration value="M"/>
<xs:enumeration value="S"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="myClass">
<xs:complexType>
<xs:attribute name="myEnum" type="myEnumSimpleType">
</xs:complexType>
</xs:element>
That will generate a JAXB class (let's call it the 'artificial JAXB class).
Then you can run xjc on the larger XSD and customize the generation to make use of this type for the particular elements.
Alternately, if the JAXB generation from this external XSD is a one-time operation (and then you put the JAXB-generated code in your SVN/Git for instance), then you can rewrite that potion of the code to use your 'artificial' JAXB type instead.
Another you may want to try is to have your binding customization
<globalBindings typesafeEnumMemberName="generateName">
not be a global one, but use expression to try to nail it exactly on this type. It is likely that JAXB will generate a new class for each occurrence, even though they are going to be the same.
Since I find xpath tedious, I would test it out quickly on a local copy of that big XSD, that you modify with the namespace, e.g.
<xs:element name="myClass">
<xs:complexType>
<xs:attribute name="myEnum" >
<xs:simpleType >
<xs:annotation>
<xs:appinfo>
<jaxb:typesafeEnumClass/>
</xs:appinfo>
</xs:annotation> <xs:restriction base="xs:string">
<xs:maxLength value="1"/>
<xs:enumeration value="C"/>
<xs:enumeration value="M"/>
<xs:enumeration value="S"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
Related
I have the following schema which I would like to create an enum class
<xs:simpleType name="TopicValuesType">
<xs:union memberTypes="xs:string">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="APPLE"/>
<xs:enumeration value="BANANA"/>
<xs:enumeration value="ORANGE"/>
<xs:enumeration value="#"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
<xs:complexType name="TopicType">
<xs:attribute name="name" type="TopicValuesType" use="required"/>
</xs:complexType>
I've tried to create a binding class but it doesn't work.
<bindings schemaLocation="MySchema.xsd">
<globalBindings typesafeEnumBase="xs:string" typesafeEnumMemberName="generateName" />
</bindings>
I've read this post XJC does not generate enum inside xs:union where it's not possible to create enum.
Is there any other way to create enum out of this schema? Unfortunately I'm unable to edit the schema because it's from a third party.
I'm using maven jaxb2
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.14.0</version>
I've got two example files: note.xml and note.xsd. I would like to combine this two files using DataSet and create output XML file, based on this operation. How can i do it?
note.xml
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
note.xsd
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="note">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string"/>
<xs:element name="from" type="xs:string"/>
<xs:element name="heading" type="xs:string"/>
<xs:element name="body" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
UPDATE
Basically, i would like to combine XSD and XML and create output XML file. I want to use something like data table relations(DataSet)
Then after combine, we can decide based on data type(string, int..), which for example: dataform can store this.
I have got xsd with choice statement
<xs:complexType name="opt_type">
<xs:choice>
<xs:element name="opt_1_1" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xsd:string">
<xs:enumeration value="opt_1_1 value 1"/>
<xs:enumeration value="opt_1_1 value 2"/>
<xs:enumeration value="opt_1_1 value 3"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="opt_1_2" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xsd:string">
<xs:enumeration value="opt_1_2 value"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="opt_1_3" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xsd:string">
<xs:enumeration value="opt_1_3 value"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:choice>
</xs:complexType>
...
<xs:element name="opt" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
...
<xs:element name="opt_1" type="myns:opt_type" minOccurs="0"></xs:element>
...
</xs:sequence>
</xs:complexType>
</xs:element>
I need xforms (I'm working with Orbeon), which will give me, depending on users choice, xml with nodes like those:
<myns:opt_1>
<myns:opt_1_1>opt_1_1 value 1</myns:opt_1_1>
</myns:opt_1>
or
<myns:opt_1>
<myns:opt_1_1>opt_1_1 value 2</myns:opt_1_1>
</myns:opt_1>
or
<myns:opt_1>
<myns:opt_1_1>opt_1_1 value 3</myns:opt_1_1>
</myns:opt_1>
or
<myns:opt_1>
<myns:opt_1_2>opt_1_2 value</myns:opt_1_1>
</myns:opt_1>
or
<myns:opt_1>
<myns:opt_1_3>opt_1_3 value</myns:opt_1_1>
</myns:opt_1>
How can I achieve that?
How should xforms be constructed?
In short you want to change the structure of the XML (using different element names). To do this, your tools should be actions using xf:insert and xf:delete, to insert and delete elements. You need to do this "by hand", as the XForms engine will not do this for you automatically based on the schema.
Does anyone know what extra classes parameter from Java2WSDL tool mean?
Java2DSDL Reference
I am looking to answer this question, but have no success.
It is used to include those types in WSDL definition whose parents appears as return types or parameters. Consider very simple example:
public class DemoService {
public Animal pickRandomAnimal() {
return new Dog(); // or any other animal
}
}
.. where Animal is an interface. At a WSDL generation time Axis2 will not be able to automatically trace all possible implementations of Animal that you might expect to be returned. Without extraClasses you'll get something like this:
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://demo.com/xsd">
<xs:complexType name="Animal">
<xs:sequence>
<xs:element minOccurs="0" name="animalName" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
.. and if you add extraClasses="com.demo.Dog", you'll cover all types you need in your WSDL schema part:
<xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://demo.com/xsd">
<xs:complexType name="Animal">
<xs:sequence>
<xs:element minOccurs="0" name="animalName" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Dog">
<xs:sequence>
<xs:element minOccurs="0" name="animalName" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
I'm trying to generate classes from an xsd but I'm getting the following exception when trying to customize a simple type:
com.sun.istack.SAXParseException2: A type safe enum customization is specified to a simple type that cannot be mapped to a type safe enum.
The declaration of the simple type that throws the exception is as follows:
<xs:simpleType name="BroadcastAlertsItem">
<xs:annotation>
<xs:appinfo>
reserved (0)
broadcastAlertsAccepted (1)
broadcastAlertsNotAccepted (2)
</xs:appinfo>
</xs:annotation>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:unsignedInt">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="2"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="reserved"/>
<xs:enumeration value="broadcastAlertsAccepted"/>
<xs:enumeration value="broadcastAlertsNotAccepted"/>
</xs:restriction>
</xs:simpleType>
</xs:union>
</xs:simpleType>
And this is the binding from the binding customization file:
<jaxb:bindings node="//xs:simpleType[#name='BroadcastAlertsItem']">
<jaxb:typesafeEnumBase name="BroadcastAlertsItem">
<jaxb:typesafeEnumMember name="reserved"/>
<jaxb:typesafeEnumMember name="broadcastAlertsAccepted"/>
<jaxb:typesafeEnumMember name="broadcastAlertsNotAccepted"/>
</jaxb:typesafeEnumBase>
</jaxb:bindings>
As you will suppose, I have tried many more ways to achieve this goal :(
Does anybody know if there is a way to bind that simple type without modifying the xsd file?
Thank you very much.