jQuery in Action, 2nd edition*
The moose likes XML and Related Technologies and the fly likes what is the XML Schema declaration for java.util.List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "what is the XML Schema declaration for java.util.List" Watch "what is the XML Schema declaration for java.util.List" New topic
Author

what is the XML Schema declaration for java.util.List

Bitan Biswas
Greenhorn

Joined: Aug 05, 2011
Posts: 12
I'm defining a xml schema to generate a wsdl. for that i need to create such a schema which should be similar to a java class.

My java class is

public class GetDesignationResponse {

private List<Designation> designation;

public List<Designation> getDesignation() {
return designation;
}

public void setDesignation(List<Designation> designation) {
this.designation = designation;
}
}



public class Designation {

private int desigId;
private String desigName;

// getters setters
}

my xml schema file is something like


<xs:element name="desigId" type="xs:int" />
<xs:element name="desigName" type="xs:string" />

<xs:element name="designation" tns:minOccurs="0" tns:maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element ref="tns:desigId" />
<xs:element ref="tns:desigName" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:element name="getDesignationResponse">
<xs:complexType>
<xs:sequence>
<xs:element ref="tns:designation" />
</xs:sequence>
</xs:complexType>
</xs:element>

but when i generating the java file by "wsimport" from wsdl,
the GetDesignationResponse java file is not having the List<Designation> property rather Desingation property.

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"designation"
})
@XmlRootElement(name = "getDesignationResponse")
public class GetDesignationResponse {

@XmlElement(required = true)
protected Designation designation; // i want this to be like ---> protected List<Designation> designation;


public Designation getDesignation() {
return designation;
}

public void setDesignation(Designation value) {
this.designation = value;
}
}


can anybody tell me how to declare schema in xml similar to List<Object>?
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2229
    
    7

You are in luck, there is a "list' data type in XML schema. here


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5
Bitan Biswas
Greenhorn

Joined: Aug 05, 2011
Posts: 12
yes, i have data type for list. but it is capable for java primitives only.. not for java objects. i have already tried that.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2229
    
    7

Then your Designation is definitely not a simple type. Have you try setting the itemType to your complex Designation type?

Edit: your Designation type can also be simpleType in xml. here shows an example.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3

Never come across minOccurs and maxOccurs attributes by chance having a definition in the namespace of prefix tns whatever it is - unless you tell us how they are defined. If they are attached to xs namespace, their occurrence in that position of xs:element is erroneous.

Most likely, you simply mean this.


Then you want a list of some kind.
Bitan Biswas
Greenhorn

Joined: Aug 05, 2011
Posts: 12
thanks, g tsuji... it worked.
 
Consider Paul's rocket mass heater.
 
subject: what is the XML Schema declaration for java.util.List
 
Similar Threads
Axis2 POJO web service - wsdl generating xs:anyType
JAXB : Java complilation error after XJC Compilation
XML Validation using JAXB-2.0
XML schema fails to load
JAXB issue