2016-01-06 44 views
1

我叫一个SOAP服务,并希望使用XQuery将其转换成JSON,但总是结果说,有错误标记:转化SOAP输出到JSON问题

这是SOAP:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:NS1="http://www.inspirejo.com/soapwheather" <soapenv:Body> 
    <NS1:wheatherResponse> 
    <CountryName>United states</CountryName> 
    <countryCode>USA</countryCode> 
    <cityCode>NY</cityCode> 
    <cityName>New york</cityName> 
    <respCode>****************</respCode> 
    <minDegree>12</minDegree> 
    <maxDegree>21</maxDegree> 
    <hummedity>21</hummedity> 
    <windspeed>20</windspeed> 
    </NS1:wheatherResponse> 
</soapenv:Body> 
</soapenv:Envelope> 

的XQuery代码:

xquery version "1.0"; 
declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; 
declare namespace xsd = "http://www.w3.org/2001/XMLSchema"; 
declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/"; 
declare namespace NS1 = "http://www.inspirejo.com/soapwheather/"; 
declare option output:method "json"; 
declare option jsoniq-version "0.4.42"; 

let $soapresult := soapenv:Envelope/soapenv:Body/NS1:wheatherResponse 
return{ 
    "countryCode" : $soapresult/countryCode, 
    "cityCode" : $soapresult/cityCode, 
    "countryName" : $soapresult/countryName, 
    "cityName" : $soapresult/cityName, 
    "minDegree" : $soapresult/minDegree, 
    "maxDegree" : $soapresult/maxDegree, 
    "hummedity" : $soapresult/hummedity, 
    "windSpeed" : $soapresult/windSpeed 
} 

我固定令牌错误,但仍然输出和变换的输出是: illegal character '{' at offset 1 of http://192.168.0.211:12019/inspire/wservice/wheatherRequest?countryCode=USA&cityCode=NY

.{. 
    "countryCode" : null, 
    "cityCode" : null, 
    "countryName" : null, 
    "cityName"  : null, 
    "minDegree" : null, 
    "maxDegree" :null, 
     .. etc. all transformation result is null. 
} 

回答

0

对NS1的命名空间定义为从在SOAP信封中所使用的不同的(结束/在格兰声明)。 下面的代码在Zorba http://try.zorba.io/queries/xquery中进行测试,并给出正确的输出。注意围绕这些值的fn:字符串。如果你不使用它,你会得到完整的元素。

declare namespace output = "http://www.w3.org/2010/xslt-xquery-serialization"; 
declare namespace soapenv = "http://schemas.xmlsoap.org/soap/envelope/"; 
declare namespace NS1 = "http://www.inspirejo.com/soapwheather"; 

let $soapEnv := <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:NS1="http://www.inspirejo.com/soapwheather"> 
<soapenv:Body> 
    <NS1:wheatherResponse> 
<CountryName>United states</CountryName> 
<countryCode>USA</countryCode> 
<cityCode>NY</cityCode> 
<cityName>New york</cityName> 
<respCode>****************</respCode> 
<minDegree>12</minDegree> 
<maxDegree>21</maxDegree> 
<hummedity>21</hummedity> 
<windspeed>20</windspeed> 
</NS1:wheatherResponse> 
</soapenv:Body> 
</soapenv:Envelope> 

let $soapresult := $soapEnv//NS1:wheatherResponse 
return { 
"countryCode" : fn:string($soapresult/countryCode), 
"cityCode" : fn:string($soapresult/cityCode), 
"countryName" : fn:string($soapresult/countryName), 
"cityName" : fn:string($soapresult/cityName), 
"minDegree" : fn:string($soapresult/minDegree), 
"maxDegree" : fn:string($soapresult/maxDegree), 
"hummedity" : fn:string($soapresult/hummedity), 
"windSpeed" : fn:string($soapresult/windSpeed) 
}