格式化 XSD 以特定方式生成字符串数组



我没有很多使用 XSD 文件或 SOAP 的经验,所以很抱歉,如果这是一个微不足道的请求。

我正在构建一个应用程序,通过Quickbooks Web Connector与Quickbooks Desktop进行通信,我需要我的Web服务在调用身份验证(strUserName,strPassword(时返回字符串数组。

我正在使用XJC插件从XSD文件仅供参考创建我的Java POJO类。

我目前的 XSD 响应定义格式如下:

<xsd:element name="authenticateResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="authenticateResult" type="xsd:string" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

我也尝试过这样格式化它:

<xsd:element name="authenticateResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="authenticateResult">
<xsd:simpleType>
<xsd:list itemType="xsd:string"/>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

我的 Spring 服务器正在返回对该方法的调用,如下所示:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns2:authenticateResponse xmlns:ns2="http://developer.intuit.com/">
<ns2:authenticateResult>291bc0f2-b22b-40b7-9326-8bb946cf91ca</ns2:authenticateResult>
<ns2:authenticateResult/>
</ns2:authenticateResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

但是我需要像这样返回它们:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://developer.intuit.com/">
<SOAP-ENV:Body>
<ns1:authenticateResponse>
<ns1:authenticateResult>
<ns1:string>15c9ce293bd3f41b761c21635b14fa06</ns1:string>
<ns1:string></ns1:string>
</ns1:authenticateResult>
</ns1:authenticateResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

注意:父对象应该是"ns2:authenticateResult",其子对象应该是"ns2:string">作为元素。

如何使其正确返回?

在 XSD 模型中,每个 XML 标记都需要一个相应的 XSD 元素声明。XSD 没有"字符串"标记的任何元素定义。因此,您需要将"string"元素显式声明为"authenticateResponse"元素的子元素:

<xsd:element name="authenticateResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="authenticateResult">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="string" type="xsd:string" maxOccurs="unbounded">
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

最新更新