Java 格式化XSD以以特定方式生成字符串数组
我没有很多使用XSD文件或SOAP的经验,如果这是一个微不足道的请求,那么很抱歉 我正在构建一个应用程序,通过Quickbooks Web连接器与Quickbooks桌面通信,我需要我的Web服务在调用身份验证(strUserName、strPassword)时返回字符串数组 我正在使用XJC插件从XSD文件FYI创建我的JavaPOJO类 我目前的XSD响应定义格式如下:Java 格式化XSD以以特定方式生成字符串数组,java,spring,xsd,quickbooks,xjc,Java,Spring,Xsd,Quickbooks,Xjc,我没有很多使用XSD文件或SOAP的经验,如果这是一个微不足道的请求,那么很抱歉 我正在构建一个应用程序,通过Quickbooks Web连接器与Quickbooks桌面通信,我需要我的Web服务在调用身份验证(strUserName、strPassword)时返回字符串数组 我正在使用XJC插件从XSD文件FYI创建我的JavaPOJO类 我目前的XSD响应定义格式如下: <xsd:element name="authenticateResponse"> <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>
<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>
我的Spring服务器返回对方法的调用,如下所示:
<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>
<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>
291bc0f2-b22b-40b7-9326-8bb946cf91ca
但我需要他们像这样被归还:
<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>
<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>
15c9ce293bd3f41b761c21635b14fa06
注意:父对象应为'ns2:authenticateResult',其子对象应为'ns2:string',作为元素
如何使其正确返回?在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>
在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>