I want to create classes from a standard schema learning object model. The schema appears to be broken due to a lowercased type. Is there any way that I can generate classes with jaxb in a "case insensitve" mode?
Here is the problem where the conflict comes out:
<xs:complexType name="Duration">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="duration" type="DurationValue"/>
<xs:element name="description" type="description"/>
<xs:group ref="ex:customElements"/>
</xs:choice>
</xs:complexType>
<xs:complexType name="duration">
<xs:complexContent>
<xs:extension base="Duration">
<xs:attributeGroup ref="ag:duration"/>
<xs:attributeGroup ref="ex:customAttributes"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
I have rename the "duration" tag to "customDuration" and I have change the references as well and it works.
Thank you!
I think that you should change the schema in order to have Duration and duration_, generate JAXB objects and then change your JAXB classes generated in order to adapt them to the origina WSDL. For example, in Java:
#XmlElement(name = "Duration")
protected String duration;
#XmlElement(name = "duration")
protected String duration_;
(I have simplified the types in the example). Hope anyway you find a better solution.
This was already answered but Hope this will help some one else , use -XautoNameResolution so that new classes will be generated whenever it encounters two elements with same name (Case insensitive). I used it as following
xjc -d src -p com.sample -wsdl somewsdl.wsdl -XautoNameResolution
Related
I'm trying to connect to a C#/NET (*.svc) webservice. I have to use java, thus wsdl2java is my choice.
Problem: somehow the targeting webservice defines lots of elements dublicate. This might be due to the nature of C# or whatever.
There are like 100+ elements as follows:
<xs:complexType name="Ticket">
<xs:sequence>
<xs:element minOccurs="0" name="ASegment"
nillable="true" type="tns:AnArray" />
</xs:sequence>
</xs:complexType>
<xs:element name="Ticket" nillable="true" type="tns:Ticket" />
Resulting in:
'Ticket' is already defined (org.apache.cxf:cxf-codegen-plugin:3.0.1:wsdl2java:generate-sources:generate-sources)
How can I cope with this? I read about a jaxb-binding.xml file, where I can "rename" specific elements explicit.
But if I apply this for 100+ elements, well the week has only 5 days...
Is there any way I can though auto generate the classes?
Please see this answer:
Prefixing JAXB generated classes
jaxb:nameXmlTransform is your friend.
I normally do <jaxb:elementName suffix="Element"/>.
i know that you can generate Java classes from an XSD file with JAXB or similar methods and then use them with your resulting XML files. That's not what i'm looking for though.
I was wondering if it is possible to generate a generic Java representation of the XSD itself and if there are programs that parse any random XSD and fill the Java classes with it.
For example, let's take this short excerpt from an XSD:
<xs:complexType name="pc-type">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="manufacturer" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:integer"/>
</xs:complexType>
A Java representation could be something like:
public class ComplexType{
String name;
List<Attribute> attributes;
List<Element> elements;
...
}
Does something like this exist?
There is a XSD for XSD. You can generate the JAXB classes from this xsd.xsd.
I'm using the XSOM framework to parse a batch of XSD files, and then write them into a graph db.
For every XSDeclaration, there is a possibility to check whether or not they are local, or global. In other words, whether a component is declared in the root of the XSD files, or if it's part of an anonymous type.
I would like to be able to retrieve the global parent, of which the local component is a part of but I could not find such a method anywhere in the java doc.
For example:
<xs:group name="group">
<xs:sequence>
<xs:element name="grEl1" type="xs:string" />
<xs:element name="grEl2" type="xs:string" />
<xs:element name="grEl3" type="xs:string" />
</xs:sequence>
</xs:group>
When I have the XSElementDecl with name grEl1, I check if it's local which will return true. I would then like to be able to ask that XSElementDecl in some way, to give me it's parent, which is the XSModelGroupDecl with name group.
Thanks in advance :)
I want to generate documentation for XML schemas.
My goal is to analyze the xsd file and to display it as a tree structure (with all complex / anonymous types resolved). Furthermore I need to annotate all items in that tree with their cardinality (as defined by the schema).
The following small example might help to clarify my problem.
a) the xsd file:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="client" type="clientType" />
<xs:complexType name="clientType">
<xs:sequence minOccurs="1" maxOccurs="1">
<xs:element name="first_name"/>
<xs:element name="last_name"/>
<xs:element name="address" type="addressType"
minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="addressType">
<xs:sequence>
<xs:element name="street"/>
<xs:element name="number" minOccurs="0" maxOccurs="1"/>
<xs:element name="city"/>
<xs:element name="zipcode"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
b) Output I'd like to see:
client [1]
first_name [1]
last_name [1]
address [1..n]
street [1]
number [0..1]
city [1]
zipcode [1]
Does anybody know a java based solution for this problem? Preferably based on Eclipse Schema Infoset, but I'm happy to use other libraries as well.
XSOM can normalize an XSD into a comprehensible data structure that you can loop over and print out.
Given that XSD schema are also XML you could process this as XML giving you many options for how to do this.
My preference would be to use an XSLT stylesheet with templates to match the element and complex type elements to get the output list, and further templates to match the minOccurs and maxOccurs attributes to get your cardinality.
Examples of stylsheets to do this are probably available online already.
Although not having a proper solution I would propose the following: use a tool that is capable of generating a sample XML instance based on the XSD, e.g. eclipse IDE (as it is open source it should be possible to extract the relevant code and use it within a standalone solution). This XML should be very close to the tree structure you are requiring. Then, parse the XSD and annotate the elements in the generated XML structure with the cardinalities.
I have a schema which names all its elements and complexTypes in capital letters and so all my class names are also in caps.
Can you let me know how to capture this and name the classes in CamelCase?
Ex: Snippet of XSD :
<xs:element name="REGISTRATION_DATE">
<xs:complexType mixed="true">
<xs:attribute name="UNIT" />
</xs:complexType>
</xs:element>
Currently it is generating as : REGISTRATIONDATE .
But I would like to generate class as : RegistrationDate .
Regards,
Satya
There is a plugin for XJC to do this - the CamelCase Always plugin.