English 中文(简体)
JavaWeb Service 返回字符 < > 的 & lt 和 & gt
原标题:Java WebService returns &lt and &gt for chars < >

我写了一个肥皂/网络服务, 返回一个字符串, 例如 :

"<GeocodeResponse><City>Denver</City><State>CO</State></GeocodeResponse>"

我为这个数据定义了一个方案:

<xs:element name="GeocodeResponse">
<xs:complexType>
    <xs:sequence>
        <xs:element name="City"/>
        <xs:element name="State"/>
    </xs:sequence>
</xs:complexType>
</xs:element>

并将此回复作为我网络服务方法的回复

<xs:complexType name="standardizeResponse">
  <xs:sequence>
     <GeocodeResponse/>
  </xs:sequence>
</xs:complexType>

Within the soap envelope, the Xml is escaped so instead of getting the xml I want, I get something like: &lt;GeocodeResponse&gt;&lt;City&gt;Denver&lt;/City&gt;&lt;State&gt;CO&lt;/State&gt;&lt;/GeocodeResponse&gt;

我想,通过使用这个计划 来定义什么返回 在弦的弦, 我会避免 绳子逃脱。

最佳回答

当您为 XML 处理器提供一个原始字符串时, 理解是, 字符串的含义将传递给接收器, 这样可以重建实际字符串。 这意味着处理器将避开任何保留 XML 字符( & lt; & gt; & amp;% ), 这样它们不会被错误地拼写为文档的一部分, 而不是文档中的信件 。

如果您使用 xjc 生成物体来反映 schemas (或者,更好的是, wsimport 来生成来自 WSDL 的物体和服务根条), 您可以用数据填充生成的物体, 然后用马歇尔人来构建响应信息, 然后以适当标记的 XML 方式生成响应信息。 马歇尔文件实际上提供了用于整合到各种形式( http://docs. oracle.com/javase/6/docs/ap/javaxmx/bnd/Marshaller.html < a > ) 的好例子。

我所做的假设是为了弥补缺乏上下文的情况,因此,如果这一答案似乎不适用,请按此作答,并包括实际服务终点代码,我(或其他响应者)可以重新审视。

祝你好运!

问题回答

你可以试试这个,它能解决我的问题

org.apache.axiom.om.OMElement tmpElement=org.apache.axiom.om.util.AXIOMUtil.stringToOM(Element.getText());

当您在 SOAP 信封中添加元素时, 您将会收到“ <” 和“ amp;” (而不是“ <” 和“ & amp;” ) 的适当代表 。





相关问题
IIS 6.0 hangs when serving a web-service

I am having issues with one of our web-services. It works fine on my development machine (win XP) whether I host it as a separate application or using cassini from Visual studio. Once I deploy on the ...

ASP.net web services

I am using a web service which sets the Thread.CurrentPrincipal object while logging in and soon later when another webmethod of the same web service accesses Thread.CurrentPrincipal, its different/...

Unity Container Disposing and XML Web Service

I am registering some wrapers over un-managed objects in container. How can I dispose of them at the end of the container s lifetime? Please bear in mind I have an XML Web service.

SharePoint : web service permission error

I have a sharepoint site, and I am calling a standard sharepoint web service. I create the web service request like this : wsDws.Url = this.SiteAddress + @"/_vti_bin/Dws.asmx"; When I use ...

热门标签