Java 如何在android中解析.NETWeb服务soap对象中的XML数据?

Java 如何在android中解析.NETWeb服务soap对象中的XML数据?,java,.net,web-services,xml-parsing,android-ksoap2,Java,.net,Web Services,Xml Parsing,Android Ksoap2,我不熟悉xml的概念。我从.NETWeb服务接收数据。因此,此web服务返回数据集。我使用soap对象接收此数据集结果。它以XML格式返回。我无法从返回的结果中检索数据 web服务的输出如下所示: GETRESULTSResponse{GETRESULTSResult=anyType{Users=anyType{Table1=anyType{StudentID=713; RegisterNumber=2913402; StudentName=KARTHIK M; Gender=Male; Co

我不熟悉xml的概念。我从.NETWeb服务接收数据。因此,此web服务返回数据集。我使用soap对象接收此数据集结果。它以XML格式返回。我无法从返回的结果中检索数据

web服务的输出如下所示:

 GETRESULTSResponse{GETRESULTSResult=anyType{Users=anyType{Table1=anyType{StudentID=713; RegisterNumber=2913402; StudentName=KARTHIK M; Gender=Male; CourseID=6; BranchID=27; BatchID=18; RollNumber=10SLEC603; }; }; }; }
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, METHOD_NAME1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
PropertyInfo pi = new PropertyInfo();
pi.setName("strSQL");
pi.setValue(ConstantValues.STUDENT_DETAILS);
pi.setType(ArrayList.class);
request.addProperty(pi);
envelope.setOutputSoapObject(request);

HttpTransportSE httpTransportSE = new HttpTransportSE(SOAP_ADDRESS);
SoapObject response = null;

httpTransportSE.call(SOAP_ACTION1, envelope);
response = (SoapObject)envelope.bodyIn;

String xml = response.toString();
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = XMLfunctions.numResults(doc);

if(totalCount > 0){
   NodeList nodes = doc.getElementsByTagName("Table1");
   for (int i = 0; i < nodes.getLength(); i++) {
  Element e = (Element)nodes.item(i);
  String studentId =  XMLfunctions.getValue(e, "StudentID");
  String regNo =  XMLfunctions.getValue(e, "RegisterNumber");
  String stuName =  XMLfunctions.getValue(e, "StudentName");
  String gender = XMLfunctions.getValue(e, "Gender");
   }
}
我想得到每个元素的数据。我不知道如何解析它。请帮帮我

这是我的代码片段:

 GETRESULTSResponse{GETRESULTSResult=anyType{Users=anyType{Table1=anyType{StudentID=713; RegisterNumber=2913402; StudentName=KARTHIK M; Gender=Male; CourseID=6; BranchID=27; BatchID=18; RollNumber=10SLEC603; }; }; }; }
SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, METHOD_NAME1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
PropertyInfo pi = new PropertyInfo();
pi.setName("strSQL");
pi.setValue(ConstantValues.STUDENT_DETAILS);
pi.setType(ArrayList.class);
request.addProperty(pi);
envelope.setOutputSoapObject(request);

HttpTransportSE httpTransportSE = new HttpTransportSE(SOAP_ADDRESS);
SoapObject response = null;

httpTransportSE.call(SOAP_ACTION1, envelope);
response = (SoapObject)envelope.bodyIn;

String xml = response.toString();
Document doc = XMLfunctions.XMLfromString(xml);
int numResults = XMLfunctions.numResults(doc);

if(totalCount > 0){
   NodeList nodes = doc.getElementsByTagName("Table1");
   for (int i = 0; i < nodes.getLength(); i++) {
  Element e = (Element)nodes.item(i);
  String studentId =  XMLfunctions.getValue(e, "StudentID");
  String regNo =  XMLfunctions.getValue(e, "RegisterNumber");
  String stuName =  XMLfunctions.getValue(e, "StudentName");
  String gender = XMLfunctions.getValue(e, "Gender");
   }
}
SoapObject请求=新的SoapObject(WSDL\u TARGET\u名称空间,方法\u NAME1);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
PropertyInfo pi=新的PropertyInfo();
pi.setName(“strSQL”);
pi.设定值(恒定值.学生详细信息);
set类型(ArrayList.class);
请求。添加属性(pi);
envelope.setOutputSoapObject(请求);
HttpTransportSE HttpTransportSE=新的HttpTransportSE(SOAP\U地址);
SoapObject响应=null;
httpTransportSE.call(SOAP_ACTION1,信封);
响应=(SoapObject)envelope.bodyIn;
字符串xml=response.toString();
Document doc=XMLfunctions.XMLfromString(xml);
int numResults=XMLfunctions.numResults(doc);
如果(总计数>0){
NodeList节点=doc.getElementsByTagName(“表1”);
对于(int i=0;i
我试图用这段代码解析数据。但我无法解析它。请给我提供一个简单的方法来解析soap对象响应中的xml数据,我是从.NETWebService数据集获得的


提前谢谢。

我终于找到了解决办法

        SoapObject request = new SoapObject(ConstantValues.WSDL_TARGET_NAMESPACE, ConstantValues.METHOD_NAME1);
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        PropertyInfo pi = new PropertyInfo();
        pi.setName("strSQL");
        pi.setValue(ConstantValues.STUDENT_DETAILS);
        //pi.setType(ArrayList.class);
        request.addProperty(pi);
        envelope.setOutputSoapObject(request);

        HttpTransportSE httpTransportSE = new HttpTransportSE(ConstantValues.SOAP_ADDRESS);
        SoapObject response = null;
        httpTransportSE.debug=true; 
        httpTransportSE.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"utf-8\"?>");

        httpTransportSE.call(ConstantValues.SOAP_ACTION1, envelope);
        response = (SoapObject)envelope.bodyIn;
        int totalCount = response.getPropertyCount();

        String resultString=httpTransportSE.responseDump;
        Log.d("XML data ",resultString);

        Document doc = XMLfunctions.XMLfromString(resultString);

        //int numResults = XMLfunctions.numResults(doc);

        System.out.println(totalCount);
        if(totalCount > 0){
            NodeList nodes = doc.getElementsByTagName("Table1");
            for (int i = 0; i < nodes.getLength(); i++) {
                studentData = new StudentDetailsData();
                Element e = (Element)nodes.item(i);

                studentData.setStudentId(Integer.parseInt(XMLfunctions.getValue(e, "StudentID")));
                studentData.setRegisterNo(XMLfunctions.getValue(e, "RegisterNumber"));
                studentData.setStudentName(XMLfunctions.getValue(e, "StudentName"));
                studentData.setGender(XMLfunctions.getValue(e, "Gender"));
                studentData.setCourseId(Integer.parseInt(XMLfunctions.getValue(e, "CourseID")));
                studentData.setBranchId(Integer.parseInt(XMLfunctions.getValue(e, "BranchID")));
                studentData.setBatchId(Integer.parseInt(XMLfunctions.getValue(e, "BatchID")));
                studentData.setRollNo(XMLfunctions.getValue(e, "RollNumber"));
                studentData.setSection(XMLfunctions.getValue(e, "Section"));

                result.add(studentData);

            }
        }
SoapObject请求=新的SoapObject(ConstantValues.WSDL\u TARGET\u命名空间,ConstantValues.METHOD\u NAME1);
SoapSerializationEnvelope=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
PropertyInfo pi=新的PropertyInfo();
pi.setName(“strSQL”);
pi.设定值(恒定值.学生详细信息);
//set类型(ArrayList.class);
请求。添加属性(pi);
envelope.setOutputSoapObject(请求);
HttpTransportSE HttpTransportSE=新的HttpTransportSE(ConstantValues.SOAP_地址);
SoapObject响应=null;
httpTransportSE.debug=true;
httpTransportSE.setXmlVersionTag(“”);
httpTransportSE.call(constantValue.SOAP_ACTION1,信封);
响应=(SoapObject)envelope.bodyIn;
int totalCount=response.getPropertyCount();
字符串resultString=httpTransportSE.responseDump;
Log.d(“XML数据”,resultString);
Document doc=XMLfunctions.XMLfromString(resultString);
//int numResults=XMLfunctions.numResults(doc);
系统输出打印项次(总计数);
如果(总计数>0){
NodeList节点=doc.getElementsByTagName(“表1”);
对于(int i=0;i
我希望它对某些人有用。谢谢。

我将a)不返回数据集b)使用web服务