因此,在查看代码时,读取 xml 时不会引发异常......工作正常。
public void ReadXML() throws XmlPullParserException, IOException
{
factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
xpp = factory.newPullParser();
InputStream raw = getApplicationContext().getAssets().open("trial_info.xml");
xpp.setInput(raw,null);
}
}
问题出在 doXML 方法中,我试图在其中读取文本 b/w 两个标签...例如。
<trial>
<title>The Book</title>
<author></author>
....
</trial>
生成的错误是 18:19:41.654: W/System.err(329): org.xmlpull.v1.XmlPullParserException: name expected (position:START_TAG @59:57 in java.io.InputStreamReader@44f049c8)
我认为代码可能比它需要的更复杂......但无法找出错误。谢谢
public void doXML() throws XmlPullParserException, IOException{
int eventType = XmlPullParser.START_TAG;
while(eventType != XmlPullParser.END_DOCUMENT)
{
if(eventType == XmlPullParser.TEXT && xpp.getText().equals(selectedTrial))
{
trialTxt = (TextView)findViewById(R.id.TrialAbbrevData);
trialTxt.setText(xpp.getText());
Log.d("what is this", xpp.getText());
while(!(eventType == XmlPullParser.END_TAG && xpp.getName().equals("...")))
{
if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("trialName"))
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT)
{
trialTxtDesc = (TextView)findViewById(R.id.TrialNameData);
trialTxtDesc.setText(xpp.getText());
Log.d("in loop",xpp.getText());
}
}
if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("trialDetails"))
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT)
{
trialTxtConc = (TextView)findViewById(R.id.TrialDescData);
trialTxtConc.setText(xpp.getText());
}
}
if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("trialResults"))
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT)
{
trialTxtConc = (TextView)findViewById(R.id.TrialResultsData);
trialTxtConc.setText(xpp.getText());
}
}
if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("trialConclusion"))
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT)
{
trialTxtConc=(TextView)findViewById(R.id.TrialConclusionData);
trialTxtConc.setText(xpp.getText());
}
}
if(eventType == XmlPullParser.START_TAG && xpp.getName().equals("whatItMeans"))
{
eventType = xpp.next();
if(eventType == XmlPullParser.TEXT)
{
trialTxtMeans = (TextView)findViewById(R.id.TrialWIMData);
trialTxtMeans.setText(xpp.getText());
}
}
eventType = xpp.next();
}
}
eventType = xpp.next();
}
}