有没有办法使用XMLPullParser解析多个xml?

时间:2013-06-18 03:33:37

标签: java blackberry xml-parsing xmlpullparser

我正在读取套接字上的XML数据。但是这个套接字返回多个XML文档,现在我在解析所有输出时遇到了麻烦。我如何使用XMLPullParser解析这些XML?我想把它放在一个循环中,但我怎么知道套接字返回的XML文档的数量?

这是我解析XMLDocument的代码片段。 iWbParserextends XmlPullParser

的对象
 while (iWbParser.getEventType() != XmlPullParser.END_DOCUMENT) {
       if(iWbParser.getEventType() == XmlPullParser.START_TAG){
             int nextTag = iWbParser.getMappedValue();
             switch(nextTag){
                 ...
             }
       }

 }

在while循环中,我想添加一个条件,它将继续循环,直到解析完所有数量的XML Document。

这是我从套接字读取数据的代码。这是一个客户端套接字,我向服务器发送请求,我希望响应,这是xml文档。

HttpConnection httpConnection = null;
httpConnection = establishConnectionType(httpConnection, loginURL);
httpConnection.setRequestProperty("Content-Type", "application/vnd.wv.csp.wbxml");
httpConnection.setRequestProperty("Content-Length", "" + requestCommand.length);
httpConnection.setRequestProperty("Accept",  "application/vnd.wv.csp.wbxml");
httpConnection.setRequestMethod(HttpConnection.POST);
OutputStream out = httpConnection.openOutputStream();
out.write(requestCommand);

if (httpConnection.getResponseCode()== HttpConnection.HTTP_OK){
    InputStream is = httpConnection.openInputStream();
    iResponseData = readInputStream(is);
}

httpConnection.close();
return iResponseData;

iResponseData是一个byte [],它包含我传递给上面解析器的XML文档。

0 个答案:

没有答案