0

我有一个基于 .NET 的 Web 服务,它返回 XmlDocument。

我正在使用这样的 servlet 在 JSP 文件中读取它:

CuteServlet servlet = new CuteServlet();
result = servlet.searchProperties(market_type, location, bedroom, price);

来自 CuteServlet 的 searchProperties 方法:

public SearchPropertiesResult searchProperties(String propertyMarketType,
     String location, String noOfBedroom, String price) 
{
  wsClient.Property service = new wsClient.Property();
  wsClient.PropertySoap port = service.getPropertySoap();
  return port.searchProperties(propertyMarketType, location, noOfBedroom, price);
}

searchProperties() 的返回类型是 SearchPropertiesResult。我该如何阅读它?

4

1 回答 1

0

为了解决这个问题,我读取XmlDocument(从 C# 返回) asresult并将值放入List<Object>,然后将每个 Object 转换Element为读取详细信息,如下所示:

   <% 
   ...
   wsClient.SearchPropertiesResponse.SearchPropertiesResult result 
             = servlet.searchProperties(market_type, location, bedroom, price);
   List<Object> objects = result.getContent();

   Element rootElement = (Element)objects.get(0);
   //out.println(element.getElementsByTagName("property").getLength());
   NodeList propertyList = rootElement.getElementsByTagName("property");
   out.println("<table>");
   int propertiesLength = propertyList.getLength();
   for(int i=0; i<propertiesLength; i++)
   {
   Element aProperty = (Element)propertyList.item(i);
   NodeList childNodeList = aProperty.getChildNodes();

    Element property_idElement = (Element)childNodeList.item(0);
    String property_id = property_idElement.getTextContent();

    Element street_nameElement = (Element)childNodeList.item(2);
    String street_name = (street_nameElement.getTextContent());

    ...
    String tr = "<tr><td>";
    int l = i+1;//"+l+"
    tr += "<b> </b>"+door_no+" "+street_name+", "+post+"<br/>";
    tr += description+"<br/>";
    tr += "Bedroom: "+no_of_bed+"<br/>";
    tr += "Bathroom: "+no_of_bath+"<br/>";
    ...
    tr += "Area: "+area+"<br/><br/><br/><br/>";
    tr += "</td></tr>";
    out.println(tr);
   }
   out.println("</table>");
   %>
于 2012-04-29T18:50:24.723 回答