java - SOAP WebService 中 xsd complexType 的表示问题
问题描述
我正在尝试用 java 实现一个 SOAP 网络服务。我有以下 .xsd complexType 定义:
<xsd:complexType name="BasicURL">
<xsd:annotation>
<xsd:documentation>Generic representation of an URL with a possible user-friendly label</xsd:documentation>
</xsd:annotation>
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="label" type="xsd:string"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:complexType name="URL">
<xsd:annotation>
<xsd:documentation>Extended representation of a URL with possible language and fee</xsd:documentation>
</xsd:annotation>
<xsd:complexContent>
<xsd:extension base="BasicURL">
<xsd:attribute name="lang" type="Language"/>
<xsd:attribute name="fee" type="BasicAmount"/>
<xsd:attribute name="currency" type="Currency"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
生成的 java 类如下所示:
public class BasicURL {
protected java.lang.String value;
protected java.lang.String label;
public BasicURL() {
}
...
}
和
public class URL extends BasicURL {
private Language lang;
private BasicAmount fee;
private Currency currency;
public URL() {
}
...
}
然后我有一个返回 ComplexValue 的方法,定义为
<xsd:complexType name="ComplexValue">
<xsd:annotation>
<xsd:documentation>Represent a value taking the form of a basic type, a list of values or a table of values</xsd:documentation>
</xsd:annotation>
<xsd:choice>
<xsd:element name="boolean" type="xsd:boolean"/>
<xsd:element name="number" type="xsd:long"/>
<xsd:element name="text" type="xsd:string"/>
<xsd:element name="date" type="xsd:date"/>
<xsd:element name="dateTime" type="xsd:dateTime"/>
<xsd:element name="url" type="gen:URL"/>
</xsd:choice>
</xsd:complexType>
使用以下java生成的类
public class ComplexValue {
private java.lang.Boolean _boolean;
private java.lang.Long number;
private java.lang.String text;
private java.util.Date date;
private java.util.Calendar dateTime;
private URL url;
public ComplexValue() {
}
...
}
如果我然后像这样初始化并返回 ComplexValue:
...
URL url = new URL();
url.setLabel("Google");
url.setValue("http://google.com");
url.setLang(new Language("en"));
url.setFee(new BasicAmount("14.00"));
url.setCurrency(new Currency("USD"));
ComplexValue value = new ComplexValue();
value.setURL(url);
return value;
我得到该元素的以下标记表示:
<ns15:complexValue>
<ns16:boolean />
<ns17:number />
<ns18:text />
<ns20:date />
<ns22:dateTime />
<ns25:url lang="en" fee="14.00" currency="USD" />
</ns15:complexValue>
注意它是如何只显示 URL 类型中定义的属性,而完全省略了BasicURL 类型的属性(标签)和元素( http://google.com )?为什么会这样,我该如何找出问题所在?
编辑:我应该添加其他复杂类型,例如 Court
<xsd:complexType name="Court">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"/>
<xsd:element name="webSite" type="gen:BasicURL" minOccurs="0"/>
</xsd:sequence>
<xsd:attribute name="cdbId" type="xsd:token"/>
</xsd:complexType>
有一个java类
public class Court {
private java.lang.String name;
private BasicURL webSite;
public Court() {
}
...
}
生成正确的标签
BasicURL url = new BasicURL();
url.setLabel("click here")
url.setValue("http://somesite.com");
Court court = new Court();
court.setName("somecourt");
court.setURL(url);
return court;
...
<ns12:court>
<ns12:name>somecourt</ns12:name>
<ns12:webSite label="click here">http://somesite.com</ns12:webSite>
</ns12:court>
解决方案
推荐阅读
- kubernetes - Kubernetes服务之间的通信
- ionic-framework - 离子服务稍后再试[无法加载 index.html]
- python - 具有(显然)3 个输入层和一个矩阵输出的 Python 神经网络
- parsing - browser/ballot.sol:102:18: ParserError: Expected '{' but got identifier contract token is ERC20Interface, Owned, SafeMath { ^----^
- android - 如何将每个布局与相同大小的图像相关联
- mongoose - 猫鼬:名称为“”的鉴别器已经存在
- r - 使用 flextable 包错误从 rmarkdown 生成 word 中的表
- typescript - Firebase 上传多个 Storage/Firestore
- angular - 合并两个 observables 然后转换结果
- .htaccess - 配置 htaccess 以忽略最后一个斜杠后的任何内容