gpt4 book ai didi

java - 如何在android中解析来自.NET Web服务soap对象的XML数据?

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

我对 xml 概念不熟悉。我从 .net Web 服务接收数据。此 Web 服务返回数据集作为结果。我使用肥皂对象收到此数据集结果。它以 XML 格式返回。我无法从返回的结果中检索数据。

网络服务的输出如下:

 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");
}
}

我尝试使用此代码解析数据。但我无法解析它。请提供简单的方法来解析我从 .Net webservice 数据集中获取的肥皂对象响应中的 xml 数据。

提前谢谢您。

最佳答案

最后我找到了解决方案。

        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);

}
}

我希望这对某人有用。谢谢。

关于java - 如何在android中解析来自.NET Web服务soap对象的XML数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15944364/

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