i am having issue while regenerating the JAXB classes.my previous xsd generated the below method automatically through JAXB class generation .
public List<Serializable> getContent() {
if (content == null) {
content = new ArrayList<Serializable>();
}
return this.content;
}
But my new XSD did not.
<xsd:element name="AppInfo">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="AppInfo_Type"/>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="AppInfo_Type">
<xsd:sequence>
<xsd:element ref="a" minOccurs="0" maxOccurs="unbounded"/>
<xsd:element ref="b" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="id" type="ID"/>
</xsd:complexType>
What will drive this method generation in XSD?
Add a mixed="true" attribute to your ComplexType:
<xsd:complexType name="AppInfo_Type" mixed="true">
Related
I've a WSDL XSD with request & response complex type elements defined.
<xsd:complexType name="authPartyRequest">
<xsd:sequence>
<xsd:element name="Party" type="ICI-CAAS:Party" minOccurs="1" maxOccurs="1"/>
<xsd:element name="Address" type="ICI-CAAS:Address" minOccurs="1" maxOccurs="1"/>
</xsd:sequence>
<xsd:complexType>
<xsd:complexType name="authPartyResponse">
<xsd:sequence>
<xsd:element name="Channel" type="ICI-CAAS:Channel" minOccurs="1" maxOccurs="1"/>
<xsd:element name="Event" type="ICI-CAAS:Event" minOccurs="0" maxOccurs="1"/>
<xsd:element name="Party" type="ICI-CAAS:Party" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:complexType>
and WSDL has portType definition including
<wsdl:operation name="authenticateParty">
<wsdl:input message="ICI-CAAS:authPartyRequst" />
<wsdl:output message="ICI-CAAS:authPartyResponse" /> --> method response type
</wsdl:operation>
When I generate the stubs using JAX-RPC (with WAS 6.1 run time) I'm seeing port type interface is generated with operation having response as 'void'. How ever I see request parameter is passed correctly.
public interface AuthManagerService_PortType extends java.rmi.Remote
{
public void authenticateParty(AuthPartyRequest req); --> generating response type 'void'
}
Can any one please help on priority?
How would you design a jaxb element around this xml for JAX-RS
<activity>
<code>Purchase</code>
<description> Purchase and sell </description>
<deals>
<deal key="name"> buy</deal>
<deal key="isactive"> True </deal>
<deal key="isgood"> False </deal>
<deal key="costcode"> FINCOM </deal>
<deal key="opportunity"> Finance</deal>
<deals>
</activity>
From your XML file, you can define the XML schema (see following example) and let generate the Java binding from it.
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="activity">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="code" type="xsd:string" />
<xsd:element name="description" type="xsd:string" />
<xsd:element name="deals">
<xsd:complexType>
<xsd:sequence maxOccurs="unbounded">
<xsd:element name="deal">
<xsd:complexType>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="key" type="xsd:string" />
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
#XmlRootElement(name = "activity")
#XmlAccessorType(XmlAccessType.FIELD)
public class Activity {
#XmlElement
private String code;
#XmlElement
private String description ;
#XmlElementWrapper
#XmlElement(name="detail")
public List<Detail> details = new ArrayList<Detail>();
public Activity() {}
and have a Detail class as follows
#XmlRootElement(name = "detail")
#XmlAccessorType(XmlAccessType.FIELD)
public class Detail {
#XmlAttribute
private String key;
#XmlValue
private String value;
folks, i need your help with the following.
my xml looks like this:
<Images>
<Image ImageId="1" ImageFile="a.png"/>
<Image ImageId="2" ImageFile="b.png"/>
<Image ImageId="3" ImageFile="c.png"/>
<Image ImageId="4" ImageFile="d.png"/>
<Image ImageId="5" ImageFile="e.png"/>
</Images>
<Banners>
<Banner BannerId="1" ImageId="2"/>
<Banner BannerId="43" ImageId="3"/>
<Banner BannerId="45" ImageId="4"/>
<Banner BannerId="596" ImageId="2"/>
<Banner BannerId="6" ImageId="2"/>
</Banners>
i need to create an xsd that will restrict ImageId values in Banner elements to those appearing in Images. Is it possible?
Yes; the XML schema components you need are key/keyref:
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="sample">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Images">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="Image">
<xsd:complexType>
<xsd:attribute name="ImageId" type="xsd:unsignedByte" use="required"/>
<xsd:attribute name="ImageFile" type="xsd:string" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="Banners">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="Banner">
<xsd:complexType>
<xsd:attribute name="BannerId" type="xsd:unsignedShort" use="required"/>
<xsd:attribute name="ImageId" type="xsd:unsignedByte" use="required"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:key name="PK">
<xsd:selector xpath="Images/Image"/>
<xsd:field xpath="#ImageId"/>
</xsd:key>
<xsd:keyref name="FK" refer="PK">
<xsd:selector xpath="Banners/Banner"/>
<xsd:field xpath="#ImageId"/>
</xsd:keyref>
</xsd:element>
</xsd:schema>
Sample error message:
The key sequence '8' in Keyref fails to refer to some key.
xsd-restriction-by-value.xml is XSD 1.0 invalid.
I use cxf 2.1 and let cxf validates the soap request by setting
<jaxws:properties>
<entry key="schema-validation-enabled" value="true" />
</jaxws:properties>
I have xml schema like:
<xsd:element name="roolInfo">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="a" type="aType"/>
<xsd:element name="b" type="bType"/>
<xsd:element name="v" type="xsd:string" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
When a client sends soap message without 'element v' that is restricted by minOccurs="0" maxOccurs="unbounded", I do not understand why cxf on server side throw exception
org.apache.cxf.interceptor.Fault: Unmarshalling Error: cvc-complex-type.2.4.b: The content of element 'ns2:rootInfo' is not complete. One of '{v}' is expected.
..
Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.b: The content of element 'ns2:rootInfo' is not complete. One of '{v}' is expected.
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidComplexType(XMLSchemaValidator.java:3158)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.elementLocallyValidType(XMLSchemaValidator.java:3105)
at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.processElementContent(XMLSchemaValidator.java:3007)
Any suggestions ??
Thank you
I'm working with XSD and I have a xsd:choice with many xsd:elements in it. Now I want to simplify it a little bit and therefore I've grouped the xsd:elements, so that I can outsource (and reuse) them in separate xsd:elements.
Before:
<!-- main.xsd -->
<xsd:element name="account">
<xsd:complexType>
<xsd:choice>
<xsd:element name="login-id" type="xsd:string" />
<xsd:element name="login-username" type="xsd:string" />
<xsd:element name="login-password" type="xsd:string" />
<xsd:element name="login-note" type="xsd:string" />
<xsd:element name="contact-name" type="xsd:string" />
<xsd:element name="contact-address" type="xsd:string" />
<xsd:element name="contact-phone" type="xsd:string" />
<xsd:element name="contact-note" type="xsd:string" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
After:
<!-- main.xsd -->
<xsd:include schemaLocation="outsourced.xsd" />
<xsd:element name="account">
<xsd:complexType>
<xsd:choice>
<xsd:element ref="login" />
<xsd:element ref="contact" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
<!-- outsourced.xsd -->
<xsd:element name="login">
<xsd:complexType>
<xsd:choice>
<xsd:element name="login-id" type="xsd:string" />
<xsd:element name="login-username" type="xsd:string" />
<xsd:element name="login-password" type="xsd:string" />
<xsd:element name="login-note" type="xsd:string" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:element name="contact">
<xsd:complexType>
<xsd:choice>
<xsd:element name="contact-name" type="xsd:string" />
<xsd:element name="contact-address" type="xsd:string" />
<xsd:element name="contact-phone" type="xsd:string" />
<xsd:element name="contact-note" type="xsd:string" />
</xsd:choice>
</xsd:complexType>
</xsd:element>
Sadly this creates a new Classes 'login' and 'contact' when generating Java-Source from it, what I want to avoid. Is there any way to outsource the grouped xsd:elements to simplify the xsd:choice?
I'm not sure exactly what you're looking for, but it should be one of the following:
you either want to simplify the name of the generated field so instead of n1n2n3 you get something more readable; in this case I suggest to go with this solution presented here
I suggest you to read Blaise's blog here and here - it should help understand your solution or at least how to better formulate your question.
UPDATE: Ok, what you need to do is to wrap those two groups of xsd:elements with an xsd:sequence and then play with the bindings file to get what you want (I assume you're using JAXB).
UPDATE 2: So it sounds like you are using JAXB. Then if you take the schema below, I believe it gives you what you want, reuse (by referencing model groups) and no new classes. I'll post both artifacts but I suggest you also try it (I've used NetBeans) to see what's going on (also write a test client in Java that uses the class, look at what a developer will see, etc.) and if it is still not what you want, use the results of your attempt to illustrate some more your question.
XSD:
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="account">
<xsd:complexType>
<xsd:choice>
<xsd:group ref="login"/>
<xsd:group ref="contact"/>
</xsd:choice>
</xsd:complexType>
</xsd:element>
<xsd:group name="login">
<xsd:sequence>
<xsd:element name="login-id" type="xsd:string"/>
<xsd:element name="login-username" type="xsd:string"/>
<xsd:element name="login-password" type="xsd:string"/>
<xsd:element name="login-note" type="xsd:string"/>
</xsd:sequence>
</xsd:group>
<xsd:group name="contact">
<xsd:sequence>
<xsd:element name="contact-name" type="xsd:string"/>
<xsd:element name="contact-address" type="xsd:string"/>
<xsd:element name="contact-phone" type="xsd:string"/>
<xsd:element name="contact-note" type="xsd:string"/>
</xsd:sequence>
</xsd:group>
</xsd:schema>
Java Generated class (default, no custom bindings, removed irrelevant content):
package sequnderchoice;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"loginId",
"loginUsername",
"loginPassword",
"loginNote",
"contactName",
"contactAddress",
"contactPhone",
"contactNote"
})
#XmlRootElement(name = "account")
public class Account {
#XmlElement(name = "login-id")
protected String loginId;
#XmlElement(name = "login-username")
protected String loginUsername;
#XmlElement(name = "login-password")
protected String loginPassword;
#XmlElement(name = "login-note")
protected String loginNote;
#XmlElement(name = "contact-name")
protected String contactName;
#XmlElement(name = "contact-address")
protected String contactAddress;
#XmlElement(name = "contact-phone")
protected String contactPhone;
#XmlElement(name = "contact-note")
protected String contactNote;
public String getLoginId() {
return loginId;
}
public void setLoginId(String value) {
this.loginId = value;
}
public String getLoginUsername() {
return loginUsername;
}
public void setLoginUsername(String value) {
this.loginUsername = value;
}
public String getLoginPassword() {
return loginPassword;
}
public void setLoginPassword(String value) {
this.loginPassword = value;
}
public String getLoginNote() {
return loginNote;
}
public void setLoginNote(String value) {
this.loginNote = value;
}
public String getContactName() {
return contactName;
}
public void setContactName(String value) {
this.contactName = value;
}
public String getContactAddress() {
return contactAddress;
}
public void setContactAddress(String value) {
this.contactAddress = value;
}
public String getContactPhone() {
return contactPhone;
}
public void setContactPhone(String value) {
this.contactPhone = value;
}
public String getContactNote() {
return contactNote;
}
public void setContactNote(String value) {
this.contactNote = value;
}
}