尝试使用以下代码解析 res/xml 中的 xml 文件。但是当启动项目时,它显示异常“没有这样的文件/目录”。代码中是否有任何错误?立即给我一个答案。在此先感谢。
try
{
DocumentBuilderFactory docBuilderFactory=DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder=docBuilderFactory.newDocumentBuilder();
*Document doc=docBuilder.parse(new File("project_data.xml"));*
NodeList projects=doc.getElementsByTagName("PROJECTDESC");
for(int i=0;i<projects.getLength();i++)
{
Element project=(Element)projects.item(i);
ProjectData projectdata=new ProjectData(null, null, null, null, null, null);
projectdatas.add(projectdata);
projectdata.setProject(project.getFirstChild().getNodeValue());
projectdata.getProject();
}
}
catch (Throwable t) {
Toast.makeText(this, "Request failed: "+t.toString(), 4000).show();
}
XML 文件是
<?xml version="1.0" encoding="ISO-8859-1"?>
<Results>
<Row>
<PROJECTID>1000</PROJECTID>
<PROJECTDESC>ERP Tool</PROJECTDESC>
<MANAGER>John Jakes</MANAGER>
<SPONSOR>Gregory Mallor</SPONSOR>
<STARTDATE>02-01-2010</STARTDATE>
<PLANNEDCOMPDATE>06-21-2010</PLANNEDCOMPDATE>
<PROBABLECOMPDATE>06-30-2010</PROBABLECOMPDATE>
<STATUS>Active</STATUS>
<PLNRSK>59.5065</PLNRSK>
<EPLRSK/>
<EPRRSK/>
<BDTRSK/>
<ACTUALCOMPDATE/>
<MILESTONETOLERANCE>2</MILESTONETOLERANCE>
<ACTIVITYTOLERANCE>1</ACTIVITYTOLERANCE>
<WORKFLOWID>10002</WORKFLOWID>
<CREATED>02/10/2010 16:20:43 PM</CREATED>
</Row>
<Row>
<PROJECTID>1001</PROJECTID>
<PROJECTDESC>CMS Implementation</PROJECTDESC>
<MANAGER>Florence Marie</MANAGER>
<SPONSOR>Gregory Mallor</SPONSOR>
<STARTDATE>02-11-2010</STARTDATE>
<PLANNEDCOMPDATE>02-16-2010</PLANNEDCOMPDATE>
<PROBABLECOMPDATE>02-17-2010</PROBABLECOMPDATE>
<STATUS>Open</STATUS>
<PLNRSK/>
<EPLRSK/>
<EPRRSK/>
<BDTRSK/>
<ACTUALCOMPDATE/>
<MILESTONETOLERANCE>1</MILESTONETOLERANCE>
<ACTIVITYTOLERANCE>1</ACTIVITYTOLERANCE>
<WORKFLOWID>10004</WORKFLOWID>
<CREATED>02/10/2010 17:07:14 PM</CREATED>
</Row>
<Row>
<PROJECTID>1002</PROJECTID>
<PROJECTDESC>Key Account Manager Recruiting</PROJECTDESC>
<MANAGER>Florence Marie</MANAGER>
<SPONSOR>John Jakes</SPONSOR>
<STARTDATE>02-11-2010</STARTDATE>
<PLANNEDCOMPDATE>02-13-2010</PLANNEDCOMPDATE>
<PROBABLECOMPDATE>02-13-2010</PROBABLECOMPDATE>
<STATUS>Open</STATUS>
<PLNRSK/>
<EPLRSK/>
<EPRRSK/>
<BDTRSK/>
<ACTUALCOMPDATE/>
<MILESTONETOLERANCE>1</MILESTONETOLERANCE>
<ACTIVITYTOLERANCE>1</ACTIVITYTOLERANCE>
<WORKFLOWID>10009</WORKFLOWID>
<CREATED>02/10/2010 17:07:18 PM</CREATED>
</Row>
<Row>
<PROJECTID>1003</PROJECTID>
<PROJECTDESC>Fast Food Regional Market Analysis</PROJECTDESC>
<MANAGER>John Jakes</MANAGER>
<SPONSOR>Florence Marie</SPONSOR>
<STARTDATE>02-12-2010</STARTDATE>
<PLANNEDCOMPDATE>02-16-2010</PLANNEDCOMPDATE>
<PROBABLECOMPDATE>02-16-2010</PROBABLECOMPDATE>
<STATUS>Open</STATUS>
<PLNRSK/>
<EPLRSK/>
<EPRRSK/>
<BDTRSK/>
<ACTUALCOMPDATE/>
<MILESTONETOLERANCE>2</MILESTONETOLERANCE>
<ACTIVITYTOLERANCE>1</ACTIVITYTOLERANCE>
<WORKFLOWID>10010</WORKFLOWID>
<CREATED>02/10/2010 17:07:22 PM</CREATED>
</Row>
<Row>
<PROJECTID>1004</PROJECTID>
<PROJECTDESC>ss</PROJECTDESC>
<MANAGER>John Jakes</MANAGER>
<SPONSOR>Gregory Mallor</SPONSOR>
<STARTDATE>02-11-2010</STARTDATE>
<PLANNEDCOMPDATE>02-16-2010</PLANNEDCOMPDATE>
<PROBABLECOMPDATE>02-17-2010</PROBABLECOMPDATE>
<STATUS>Open</STATUS>
<PLNRSK/>
<EPLRSK/>
<EPRRSK/>
<BDTRSK/>
<ACTUALCOMPDATE/>
<MILESTONETOLERANCE>1</MILESTONETOLERANCE>
<ACTIVITYTOLERANCE>1</ACTIVITYTOLERANCE>
<WORKFLOWID>10080</WORKFLOWID>
<CREATED>06/27/2010 19:16:26 PM</CREATED>
</Row>
</Results>