【问题标题】:Formatting an XSD to produce an Array of Strings in a specific way格式化 XSD 以特定方式生成字符串数组
【发布时间】:2019-12-10 20:06:46
【问题描述】:

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

我正在构建一个应用程序以通过 Quickbooks Web 连接器与 Quickbooks Desktop 进行通信,并且我需要我的 Web 服务在调用 authentication(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'作为元素。

我怎样才能让它正确返回?

【问题讨论】:

    标签: java spring xsd quickbooks xjc


    【解决方案1】:

    在 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 2012-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多