2017-02-16 30 views
0

我有以下示例XML消息:解析SOAP味精與gSOAP的

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP-ENV:Header> 
     <to>...</to> 
     <from>...</from> 
     <id>..</id> 
     <relatesTo>...</relatesTo> 
     <action>...</action> 
     <version>...</version> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body> 
     <customComplexElement> 
      <a>a_v</a> 
      <b>b_v</b> 
      <c>c_v</c> 
      <d>d_v</d> 
      <e>e_v</e> 
      <f>f_v</f> 
     </customComplexElement> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

我從中產生與使用的在線工具之一的XSD文件:

<?xml version="1.0"?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified"> 
<import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"></import> 
    <xs:element name="to" type="xs:string"/> 
    <xs:element name="from" type="xs:string"/> 
    <xs:element name="id" type="xs:string"/> 
    <xs:element name="relatesTo" type="xs:string"/> 
    <xs:element name="action" type="xs:string"/> 
    <xs:element name="version" type="xs:string"/> 
    <xs:element name="customComplexElement"> 
    <xs:complexType> 
     <xs:sequence> 
     <xs:element type="xs:string" name="a"/> 
     <xs:element type="xs:string" name="b"/> 
     <xs:element type="xs:string" name="c"/> 
     <xs:element type="xs:string" name="d"/> 
     <xs:element type="xs:string" name="e"/> 
     <xs:element type="xs:string" name="f"/> 
     </xs:sequence> 
    </xs:complexType> 
    </xs:element> 
</xs:schema> 

然後我產生適當的頭文件與wsdl2h.exe,然後用soapcpp2.exe編譯器進行編譯。 然後我嘗試用函數soap_read_customComplexElement()讀取xml文件,我得到的全部是SOAP_TAG_MISMATCH。這種方法似乎工作,如果我擺脫所有的肥皂東西的消息,但我不知道是否有一些函數在gSOAP解析SOAP信封,標題和正文?

回答

1

我有同樣的問題。但我已經修好了。 所以,在我的情況下,我使用這一行代碼。

struct soap *soap = soap_new1(SOAP_C_UTFSTRING | SOAP_XML_IGNORENS | SOAP_XML_TREE); 

關鍵放慢參數是SOAP_XML_IGNORENS。該參數忽略名稱空間。

SOAP_XML_IGNORENS in: ignores the use of XML namespaces in input 

這個問題的根源在於你沒有在你的主體內容中聲明命名空間。那爲什麼gSoap不知道如何轉換這個xml。

這不會被轉換,因爲gSOAP的不知道什麼是NS4:

<ns4:ParseKeywords><ns4:Keyword>Hello</ns4:Keyword></ns4:ParseKeywords> 

但是,如果我聲明的命名空間將被轉換

<ns4:ParseKeywords xmlns:ns4="com.idurdyev.idcommerce:ParseKeywords:1.0"><ns4:Keyword>Hello</ns4:Keyword></ns4:ParseKeywords>