我在xml解析时遇到问题。我已成功运行,如果我有所选项目(课程)所需的数据并返回成功的代码1(即pcode),这不是问题,但问题是我没有所选项目的数据(当然),它返回代码0(pcode 0)。
我的问题是,我在解析过程中遇到了问题。
输入; <Es_Request><Data><UserId>913</UserId><SchoolId>1</SchoolId><CourseId>977</CourseId></Data></Es_Request>
来自网络的回应:
<Es_Response>
<Es_Session_Id></Es_Session_Id>
<Bpn_Request_Id></Bpn_Request_Id>
<userIDName>913</userIDName>
<schoolID>1</schoolID>
<CourseID>977</CourseID>
<Response_Code>
<Pcode>0</Pcode>
<Scode>Unsuccessful</Scode>
<Test>977</Test>
<ROLEID>4</ROLEID>
</Response_Code>
<Data>
<message>Assignments not found for Professor & CourseId.</message>
</Data>
</Es_Response>
这是解析java代码
if (response != null) {
esResponse = XmlParser.parseAssignmentProfessorResponse(response);
if (esResponse.getResponseCode().getpCode().equalsIgnoreCase("1")) {
AssignmentDataInfo assignmentDataInfo = esResponse.getAssignmentListData().getAssignmentDataInfo();
int size = assignmentDataInfo.size();
int i = 0;
for (; i < size; i++) {
EduInterface.assignmetIdArrayList
.add(assignmentDataInfo.get(i)
.getAssignmentId());
EduInterface.assignmetNameArrayList
.add(assignmentDataInfo.get(i)
.getAssignmentName());
}
} else {
Log.d("else", "Data Not Found For this Selected Item");
}
}
这是处理程序类:
@Override
public void startElement(String uri, String localName, String qName,
Attributes atts) throws SAXException {
content = new StringBuilder();
if (localName.equalsIgnoreCase("Data")) {
assignmentListData=new AssignmentListData();
} else if (localName.equalsIgnoreCase("Assignments")) {
assignmentItems = new AssignmentItems();
}
else if (localName.equalsIgnoreCase("Es_Response")) {
esResponse=new EsResponse();
} else if (localName.equalsIgnoreCase("Response_Code")) {
responseCode=new ResponseCode();
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (localName.equalsIgnoreCase("Pcode")) {
responseCode.setpCode(content.toString());
Log.d("TAG", "Pcode Value->"+content.toString());
}
else if (localName.equalsIgnoreCase("Response_Code")) {
esResponse.setResponseCode(responseCode);
}
else if (localName.equalsIgnoreCase("AssignmentId")) {
assignmentItems.setAssignmentId(content.toString());
}
else if (localName.equalsIgnoreCase("AssignmentName")) {
assignmentItems.setAssignmentName(content.toString());
}
else if (localName.equalsIgnoreCase("Assignments")) {
assignmentDataInfo.add(assignmentItems);
}
else if (localName.equalsIgnoreCase("Data")) {
assignmentListData.setAssignmentDataInfo(assignmentDataInfo);
}
else if (localName.equalsIgnoreCase("Es_Response")) {
esResponse.setAssignmentListData(assignmentListData);
}
}
我收到了以下日志cat错误:
05-02 08:55:42.724: D/TAG(1794): Pcode Value->0
05-02 08:55:43.764: W/System.err(1794): at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:484)
05-02 08:55:43.764: W/Trace(1794): Unexpected value from nativeGetEnabledTags: 0
05-02 08:55:43.764: W/Trace(1794): Unexpected value from nativeGetEnabledTags: 0
05-02 08:55:43.764: W/System.err(1794): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:309)
05-02 08:55:43.764: W/System.err(1794): at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:267)
05-02 08:55:43.774: W/System.err(1794): at test.services.XmlParser.parseAssignmentProfessorResponse(XmlParser.java:840)
05-02 08:55:43.774: W/System.err(1794): at test.gradebook.GradeAssignmentActivity$GetDataTask.doInBackground(GradeAssignmentActivity.java:326)
05-02 08:55:43.774: W/System.err(1794): at test.gradebook.GradeAssignmentActivity$GetDataTask.doInBackground(GradeAssignmentActivity.java:1)
05-02 08:55:43.815: W/System.err(1794): at android.os.AsyncTask$2.call(AsyncTask.java:287)
05-02 08:55:44.334: E/Grade Assignment class(1794): parse failed
05-02 08:55:44.334: E/Grade Assignment class(1794): java.lang.NullPointerException
05-02 08:55:44.334: E/Grade Assignment class(1794): at test.gradebook.GradeAssignmentActivity$GetDataTask.doInBackground(GradeAssignmentActivity.java:329)
05-02 08:55:44.334: E/Grade Assignment class(1794): at test.gradebook.GradeAssignmentActivity$GetDataTask.doInBackground(GradeAssignmentActivity.java:1)
05-02 08:55:44.334: E/Grade Assignment class(1794): at android.os.AsyncTask$2.call(AsyncTask.java:287)
很抱歉很长的细节,但我想解决这个问题,请各位给我一些基本的想法。