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

问题描述 投票:1回答:1

我在使用XSD文件或SOAP方面没有很多经验,如果这是一个琐碎的请求,对不起。

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

我正在使用XJC插件从XSD文件FYI创建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>

NOTE:父对象应该是'ns2:authenticateResult',其子对象应该是'ns2:string'作为元素。

我如何使其正确返回?

java spring xsd quickbooks xjc
1个回答
0
投票

在XSD模型中,每个XML标签都需要一个相应的XSD元素声明。您的XSD没有“ string”标签的任何元素定义。因此,您需要将'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>
© www.soinside.com 2019 - 2024. All rights reserved.