Ksoap2解析器xml数据(Ksoap2 parser xml data)
我使用Ksoap2连接到这个.NET Web服务,当我输入用户ID时,我得到一个xml响应。 我只想看两个标签callTitle和callDescription。 我不需要其余的,并希望在文本中看到不包含xml代码。 有人可以帮忙吗? 我在网上找不到教程。
public class AndroidWebService extends Activity { /** Called when the activity is first created. */ private static String SOAP_ACTION = "http://tempuri.org/GetHelpDeskCalls"; private static String NAMESPACE = "http://tempuri.org/"; private static String METHOD_NAME = "GetHelpDeskCalls"; static final String URL = "https:/192.2344.123:8080/Service1.asmx"; Button getData; EditText userID; TextView data; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.helpdesk); getData = (Button) findViewById(R.id.button1); userID = (EditText) findViewById(R.id.txtFar); data = (TextView) findViewById(R.id.textView1); Thread nT = new Thread() { @Override public void run() { getData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("userID", userID.getText() .toString()); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.setOutputSoapObject(request); envelope.dotNet = true; HttpTransportSE androidHttpTransport = new HttpTransportSE( URL); try { androidHttpTransport.debug = true; androidHttpTransport.call(SOAP_ACTION, envelope); final String results = androidHttpTransport.responseDump .toString(); runOnUiThread(new Runnable() { public void run() { data.setText(results.toString()); } }); } catch (Exception e) { data.setText("Error" + e); } } }); } }; nT.start(); } }
I have used Ksoap2 to connect to this .NET web service and i get a xml response when i enter the users id. I only want to see two tags callTitle and callDescription. I don't need the rest and want to see in text not surround with xml code. can some one please help? I can't find tutorial online.
public class AndroidWebService extends Activity { /** Called when the activity is first created. */ private static String SOAP_ACTION = "http://tempuri.org/GetHelpDeskCalls"; private static String NAMESPACE = "http://tempuri.org/"; private static String METHOD_NAME = "GetHelpDeskCalls"; static final String URL = "https:/192.2344.123:8080/Service1.asmx"; Button getData; EditText userID; TextView data; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.helpdesk); getData = (Button) findViewById(R.id.button1); userID = (EditText) findViewById(R.id.txtFar); data = (TextView) findViewById(R.id.textView1); Thread nT = new Thread() { @Override public void run() { getData.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("userID", userID.getText() .toString()); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope( SoapEnvelope.VER11); envelope.setOutputSoapObject(request); envelope.dotNet = true; HttpTransportSE androidHttpTransport = new HttpTransportSE( URL); try { androidHttpTransport.debug = true; androidHttpTransport.call(SOAP_ACTION, envelope); final String results = androidHttpTransport.responseDump .toString(); runOnUiThread(new Runnable() { public void run() { data.setText(results.toString()); } }); } catch (Exception e) { data.setText("Error" + e); } } }); } }; nT.start(); } }
原文:https://stackoverflow.com/questions/18077149
最满意答案
您可以使用自执行闭包:
( function() { // some code } )();
确保变量不会发生冲突。 另外,请记住使用
var
声明变量或者它们泄漏到全局范围。如果可能的话,我只会包含一次Pusher
<script>
标签。<script src="https://d3dy5gmtp8yhk7.cloudfront.net/2.1/pusher.min.js"></script> <!-- Start Pusher Code --> <script> ( function() { var pusher = new Pusher('app_key_1'); var channel = pusher.subscribe('appname'); channel.bind('channelname', function(data) { var MyURL = 'http://www.google.com'; var newwindow=window.open(MyURL,data.cuid,'height=800,width=950,scrollbars=yes'); }); } )(); </script> <!-- End Pusher Code --> <!-- Start Pusher Code --> <script> ( function() { var pusher = new Pusher('app_key_2'); var channel = pusher.subscribe('appname'); channel.bind('channelname', function(data) { var MyURL = 'http://www.google.com'; var newwindow = window.open(MyURL,data.cuid,'height=800,width=950,scrollbars=yes'); }); } )(); </script> <!-- End Pusher Code -->
我使用了两个不同的应用程序键来确认您是否连接到两个不同的应用程序。
You can use a self-executing closure:
( function() { // some code } )();
to ensure that the variables don't clash. Also, remember to declare variables using
var
or they leak to the global scope.If possible, I would include the Pusher
<script>
tag just once.<script src="https://d3dy5gmtp8yhk7.cloudfront.net/2.1/pusher.min.js"></script> <!-- Start Pusher Code --> <script> ( function() { var pusher = new Pusher('app_key_1'); var channel = pusher.subscribe('appname'); channel.bind('channelname', function(data) { var MyURL = 'http://www.google.com'; var newwindow=window.open(MyURL,data.cuid,'height=800,width=950,scrollbars=yes'); }); } )(); </script> <!-- End Pusher Code --> <!-- Start Pusher Code --> <script> ( function() { var pusher = new Pusher('app_key_2'); var channel = pusher.subscribe('appname'); channel.bind('channelname', function(data) { var MyURL = 'http://www.google.com'; var newwindow = window.open(MyURL,data.cuid,'height=800,width=950,scrollbars=yes'); }); } )(); </script> <!-- End Pusher Code -->
I've used two different application keys to confirm that you are connecting to two different applications.
相关问答
更多-
问题似乎与在我自己的类中实例化非命名空间的Pusher类有关,该类是命名空间的。 似乎你已经通过要求命名空间分支解决了它,但无论如何: 如果在命名空间类中使用new Pusher ,那么PHP将尝试在此命名空间下找到该类: Smawt\Helpers\并且将失败并显示“Class not found”,因为此命名空间中不存在Smawt\Helpers\Pusher -没有映射。 通过使用前导反斜杠new \Pusher作为前缀,您指的是命名空间类中的全局命名空间。 另一种方法是在顶部use \Pusher; ...
-
既然你说事件创建者工作,我假设客户端功能正常,问题是: PHP代码 通过Pusher PHP库与Web API的交互。 检查PHP代码 确保打开错误报告并执行代码:
推动器集成(Pusher Integration)[2022-04-26]
Pusher保证实时功能并仅向通道发送消息。 因此,对于聊天历史记录,您需要将所有消息保存到数据库并从数据库中加载所有消息。 如何在第一次加载html页面并在开始获取频道信息之前设置好所有内容? 在第一次加载页面时,您需要使用Javascript(Ajax)来设置连接,订阅频道并绑定到事件。 您还需要获取聊天记录(来自数据库),然后附加到您的视图。 Pusher guarantees realtime functionalities and delivers messages to the channel ...您需要将作业绑定到pusher对象,而不是myChannel对象。 另外,我在我的document.ready部分中定义了这些对象,但我怀疑这很重要。 To fix this problem, I started a new app in pusher and I selected Enable Encryption and Enable Client Events. You have to start a new app, you cant just update to these settings in ...使用Javascript在同一页面中收听2个Pusher应用程序(Listening for 2 Pusher apps in same page using Javascript)[2023-07-28]
您可以使用自执行闭包: ( function() { // some code } )(); 确保变量不会发生冲突。 另外,请记住使用var声明变量或者它们泄漏到全局范围。 如果可能的话,我只会包含一次Pusher