gpt4 book ai didi

java - 在java中从WS检索正确的数据

转载 作者:行者123 更新时间:2023-11-30 04:20:28 25 4
gpt4 key购买 nike

我在此 WSDL 上运行 wsimport

http://ws.dati.comune.milano.it/opendata/wsopendata.asmx?WSDL

并生成客户端 JAX-WS 类。

现在我想使用getOpenWifi

使用此代码片段:

        String message = " ";
WSOpenData wsopendata = new WSOpenData();
GetOpenWifiResult result = wsopendata.getWSOpenDataSoap().getOpenWifi(" ");
List<Object> list = result.getContent();
for (Iterator<Object> iterator = list.iterator(); iterator.hasNext();) {

message += iterator.next().toString() + " ";
}

我正在获取消息

 [NewDataSet: null] 

我认为我做错了什么,我如何检索正确的数据集?

最佳答案

当我用 SoapUI 调用它时,我得到类似的东西

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<getOpenWifiResponse xmlns="http://comune.milano.it/">
<getOpenWifiResult>
<NewDataSet xmlns="">
<Table>
<ID>3</ID>
<Sito>Arco Della Pace</Sito>
<Zona>1</Zona>
<Attiva>1</Attiva>
<Codice>A0044</Codice>
<Coordinate>9.172460,45.475670,0.000000</Coordinate>
</Table>
<Table>
<ID>4</ID>
<Sito>Bastioni di Porta Nuova 23</Sito>
<Zona>1</Zona>
<Attiva>1</Attiva>
<Codice>E0725</Codice>
<Coordinate>9.192273,45.478577,0.000000</Coordinate>
</Table>

我认为“NewDataSet”对象将具有子对象“table”。检查生成的工件(我没有)

€编辑:尝试一下

import it.milano.comune.GetOpenWifiResponse.GetOpenWifiResult;
import it.milano.comune.WSOpenData;

import java.net.URL;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


public class Test {

/**
* @param args
*/
public static void main(String[] args) throws Exception {
WSOpenData ws = new WSOpenData(new URL("http://ws.dati.comune.milano.it/opendata/wsopendata.asmx?WSDL"));

GetOpenWifiResult rw = ws.getWSOpenDataSoap().getOpenWifi(" ");
for (Object o : rw.getContent()) {
System.out.println(o.getClass().getName());
Element e = (Element) o;
NodeList c = e.getChildNodes();

System.out.println(c);
for (int i = 0; i < c.getLength(); i++) {
Node table = c.item(i);

System.out.println("tab");

for (int i2 = 0; i2 < table.getChildNodes().getLength(); i2++) {
Node property = table.getChildNodes().item(i2);
System.out.println("\tp: " + property);
}

}

}

long x = 1;
}

}

它给了我

com.sun.org.apache.xerces.internal.dom.ElementNSImpl
[NewDataSet: null]
tab
p: [ID: null]
p: [Sito: null]
p: [Zona: null]
p: [Attiva: null]
p: [Codice: null]
p: [Coordinate: null]
tab
p: [ID: null]
p: [Sito: null]
p: [Zona: null]
p: [Attiva: null]
p: [Codice: null]
p: [Coordinate: null]
tab
p: [ID: null]
p: [Sito: null]
p: [Zona: null]
p: [Attiva: null]
p: [Codice: null]
p: [Coordinate: null]
tab
p: [ID: null]
p: [Sito: null]
p: [Zona: null]
p: [Attiva: null]
p: [Codice: null]
p: [Coordinate: null]
[...]

我相信如果你尝试一下,你就能解决这个问题

关于java - 在java中从WS检索正确的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17179096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com