Hi, I'm coding an application with a basic server client interaction
using xml parsing. I am trying to a long list of information from the
server by using an httpGet. However, when i try to send the get, and
parse it, i get the error:
ERROR/org.xmlpull.v1.XmlPullParserException: expected: /meta read:
head (position:END_TAG </head>@4:8 in
java.io.inputstreamrea...@43dde330)
what i believe is tripping up the parser is a line with this kind of
syntax:
<meta ... />
and it is just throwing the parser for a loop.
I have tried to find something on google but to no avail, and there
doesn't appear to be anything similar in the discussion archives.
any help resolving this, or getting around it, would be wonderful.
i have also noticed that i only get this error when i use a get.
when i post something to the server and parse the response, the parser
works perfectly.
here is the code i am calling the parser with:
// Execute HTTP Get
HttpResponse response = httpclient.execute(httpGet);
HttpEntity entity = response.getEntity();
//create parser with the proper properties
PullParse parser = new PullParse(PullParse.CHANNEL);
//parse the response and store it in the response object
ServerResponseMessage<Channel> message =
parser.<Channel>parse(entity);
Log.i("MyActivity", "message: "+message.getContent());
and here is the code for the parser:
public <T> ServerResponseMessage parse(HttpEntity entity)
{
//initialize the object to be returned
ServerResponseMessage<T> currentMessage = new
ServerResponseMessage();
//initialize the object that will be holding every thing
Object holder = null;
try
{
//set the input of the parser
parser.setInput(entity.getContent(), null);
//get the first event
int eventType = parser.getEventType();
//set boolean for while loop
boolean done = false;
while (!done)//start while
{
//holder for the name of the tag
String name = null;
switch (eventType)//start switch eventType
{
//when you find a start tag
case XmlPullParser.START_TAG:
//store it in name
name = parser.getName();
Log.i(TAG+"parse()", "tag: "+name);
//if it matches with channel, reset the object
if (name.equalsIgnoreCase("channel"))
{
currentMessage = new ServerResponseMessage<T>();
}
//if it doesn't match with channel, and channel has
already been created
else if (currentMessage != null)
{
//check which type of parser is being used
switch(parserType)//start switch parserType
{
//if it is the login parser
case LOGIN:
//and the tag read is login
if (name.equalsIgnoreCase("login"))
{
//add the server's response to the object
currentMessage.addContent((T) parser.nextText());
}
break;
//if it is the channel parser
case CHANNEL:
Log.i(TAG+"parse()", "case: Channel");
//if the tag matches with item
if(name.equalsIgnoreCase("item"))
{
//reset the holder variable
holder = new Channel();
Log.i(TAG+"parse()", "new Channel");
Log.i(TAG+"parse()", "holder instanceof channel: "+(holder
instanceof Channel)) ;
}
//if the holder variable has been initialized, and is an
instance of channel
else if(holder != null && holder instanceof
Channel)
{
Log.i(TAG+"parse()", "into declaration"); .
//and the tag matches with title
if(name.equalsIgnoreCase("title"))
{
//set the title of the object to the text in that
tag
((Channel)holder).setTitle(parser.nextText());
Log.i(TAG+"parse()", "set title: "+
((Channel)holder).getTitle());
}
//if the tag matches with data
else if(name.equalsIgnoreCase("data"))
{
//take the data, put it in a string array, and make it
into an arraylist
String[] temp = {parser.nextText()};
Log.i(TAG+"parse()", "content: "+temp);
//set the channel object's arraylist to the created
arraylist
((Channel)holder).setContent(new
ArrayList<String>(Arrays.asList(temp)));
}
}
break;
}//end switch parserType
}
break;
//when you find an end tag
case XmlPullParser.END_TAG:
name = parser.getName();
Log.i(TAG+"parse()", "case: End Tag: "+name);
Log.i(TAG+"parse()", "title: "+parser.nextText());
//if you find the end of item, and the holder item to the
response object
if(name.equalsIgnoreCase("item") && holder != null)
{
currentMessage.addContent((T) holder);
Log.i(TAG+"parse()", "channel added to content");
}
//if you find the channel close tag, the file is
done
else if (name.equalsIgnoreCase("channel") && currentMessage !
= null)
{
done = true;
Log.i(TAG+"parse()", "done");
}
Log.i(TAG+"parse()", "end tag break");
break;
//when you find the end of the document
case XmlPullParser.END_DOCUMENT:
Log.i(TAG+"parse()", "end document");
done = true;
}//end switch eventType
eventType = parser.next();
Log.i(TAG+"parse()", "parser.next & done: "+done);
}//end while
}
catch (XmlPullParserException e)
{
Log.e(TAG+"parse():catch", "exception"+e);
}
catch (IllegalStateException e)
{
Log.e(TAG+"parse():catch", "exception"+e);
}
catch (IOException e)
{
Log.e(TAG+"parse():catch", "exception"+e);
}
//print the content of the object to be returned with Log.i
currentMessage.printContent();
return currentMessage;
}
i apologize for the hard reading, but any help would be greatly
appreciated, thank you.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en