Java(Android)XML SAX未正确解析

Java(Android)XML SAX未正确解析,java,android,xml-parsing,sax,Java,Android,Xml Parsing,Sax,我正在开发一个应用程序,它以XML格式从远程数据源获取数据 然后,我的应用程序会将XML解析为对象,以便将数据放入适当的字段中 以下是我的数据的XML源(省略了非必要部分): 只是每次我试图检索拖车元素时,我都无法检索它 注: 我的LogCat正确地显示了我上面附加的XML元素(它可以正确地检索XML值) 有人知道这是为什么吗?不知道出了什么问题。但是调试代码总是有帮助的。建议在startElement、characters和endElement方法中添加断点,尝试调试代码。在预告片数据中,将/

我正在开发一个应用程序,它以XML格式从远程数据源获取数据

然后,我的应用程序会将XML解析为对象,以便将数据放入适当的字段中

以下是我的数据的XML源(省略了非必要部分):

只是每次我试图检索拖车元素时,我都无法检索它

注:

我的LogCat正确地显示了我上面附加的XML元素(它可以正确地检索XML值)


有人知道这是为什么吗?

不知道出了什么问题。但是调试代码总是有帮助的。建议在
startElement
characters
endElement
方法中添加断点,尝试调试代码。在预告片数据中,将/手动附加到url的末尾,就像主页url一样,然后查看它是否有效。可能这会导致end标记中断,解析器可能会跳到下一个元素。@Arunkumar,稍后会尝试使用它。@Andro Selva,你的意思是像这个缓冲区一样。toString()+“/”我会尝试使用它。在这一点上,任何建议都是非常受欢迎的。我完全不明白这一点。我可以正确地浏览网址、主页。但每次我试着烤预告片时,我什么也得不到@安德罗塞尔瓦在“/”后面加了一句似乎不起作用。
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
  <opensearch:Query searchTerms="36557"/>
  <opensearch:totalResults>1</opensearch:totalResults>
  <movies>
    <movie>
      <popularity>95126.637</popularity>
      <translated>true</translated>
      <adult>false</adult>
      <language>en</language>
      <original_name>Casino Royale</original_name>
      <name>Casino Royale</name>
      <alternative_name>James Bond - 2006 - Casino Royale</alternative_name>
      <type>movie</type>
      <id>36557</id>
      <imdb_id>tt0381061</imdb_id>
      <url>http://www.themoviedb.org/movie/36557</url>
      <overview>James Bond goes on his first ever mission as a 00. Le Chiffre is a banker to the world's terrorists. He is participating in a poker game at Montenegro, where he must win back his money, in order to stay safe among the terrorist market. The boss of MI6, known simply as M sends Bond, along with Vesper Lynd to attend this game and prevent Le Chiffre from winning. Bond, using help from Felix Leiter, Mathis and having Vesper pose as his wife, enters the most important poker game in his already dangerous career. But if Bond defeats Le Chiffre, will he and Vesper Lynd remain safe?</overview>
      <votes>1325</votes>
      <rating>6.7</rating>
      <tagline>Everyone has a past. Every legend has a beginning.</tagline>
      <certification>PG-13</certification>
      <released>2006-11-17</released>
      <runtime>144</runtime>
      <budget>150000000</budget>
      <revenue>594786758</revenue>
      <homepage>http://www.mgm.com/view/movie/233/Casino-Royale-(2006)/</homepage>
      <trailer>http://www.youtube.com/watch?v=36mnx8dBbGE</trailer>
      <categories>
        .... OMITTED ....
      </categories>
      <keywords>
        .... OMITTED ....
      </keywords>
      <studios>
        .... OMITTED ....
      </studios>
      <languages_spoken>
        <language_spoken code="en" name="English" native_name="English"/>
        <language_spoken code="fr" name="French" native_name="Français"/>
      </languages_spoken>
      <countries>
        .... OMITTED ....
      </countries>
      <images>
        .... OMITTED ....
      </images>
      <cast>
        .... OMITTED ...
      </cast>
      <version>2595</version>
      <last_modified_at>2013-08-22 00:56:17 UTC</last_modified_at>
    </movie>
  </movies>
</OpenSearchDescription>
public class MovieDetailHandler extends DefaultHandler {
private StringBuffer buffer = new StringBuffer();

private ArrayList<Movie> movieList;
private Movie movie;

private ArrayList<Image> movieImagesList;
private Image movieImage;

private ArrayList<String> movieCastList;
private String movieCast;

@Override
public void startElement(String namespaceURI, String localName,
        String qName, Attributes atts) throws SAXException {

    buffer.setLength(0);

    if (localName.equals("movies")) {
        movieList = new ArrayList<Movie>();
    }
    else if (localName.equals("movie")) {
        movie = new Movie();
    }
    else if (localName.equals("images")) {
        movieImagesList = new ArrayList<Image>();
    }
    else if (localName.equals("image")) {
        movieImage = new Image();
        movieImage.type = atts.getValue("type");
        movieImage.url = atts.getValue("url");
        movieImage.size = atts.getValue("size");
        movieImage.width = Integer.parseInt(atts.getValue("width"));
        movieImage.height = Integer.parseInt(atts.getValue("height"));
    }
}

@Override
public void endElement(String uri, String localName, String qName)throws SAXException {
    if (localName.equals("movie")) {
        movieList.add(movie);
    }
    else if (localName.equals("popularity")) { // Get Popularity information
        movie.popularity = buffer.toString();
    }
    else if (localName.equals("translated")) { // Get Translated information
        movie.translated = Boolean.valueOf(buffer.toString());
    }
    else if (localName.equals("adult")) { // Get Adult information
        movie.adult = Boolean.valueOf(buffer.toString());
    }
    else if (localName.equals("language")) { // Get Language information
        movie.language = buffer.toString();
    }
    else if (localName.equals("original_name")) { // Get Original Name information
        movie.originalName = buffer.toString();
    }
    else if (localName.equals("name")) { // Get Title information
        movie.name = buffer.toString();
    }
    else if (localName.equals("type")) { // Get Type information
        movie.type = buffer.toString();
    }
    else if (localName.equals("id")) { // Get Movie ID information
        movie.id = buffer.toString();
    }
    else if (localName.equals("imdb_id")) { // Get IMDB ID information
        movie.imdbId = buffer.toString();
    }
    else if (localName.equals("url")) { // Get TMDB URL information
        movie.url = buffer.toString();
    }
    else if (localName.equals("votes")) { // Get Votes information
        movie.votes = buffer.toString();
    }
    else if (localName.equals("overview")) { // Get Overview information
        movie.overview = buffer.toString();
    }
    else if (localName.equals("rating")) { // Get Rating information
        movie.rating = buffer.toString();
    }
    else if (localName.equals("released")) { // Get Released Date information
        movie.released = buffer.toString();
    }
    else if (localName.equals("runtime")) { // Get Runtime information
        movie.runtime = buffer.toString();
    }
    else if (localName.equals("trailer")) { // Get Trailer information
        movie.trailer = buffer.toString();
    }
    else if (localName.equals("version")) {
        movie.version = buffer.toString();
    }
    else if (localName.equals("last_modified_at")) {
        movie.lastModifiedAt = buffer.toString();
    }
    else if (localName.equals("image")) {
        movieImagesList.add(movieImage);
    }   
    else if (localName.equals("images")) {
        movie.imagesList = movieImagesList;
    }
}

@Override
public void characters(char[] ch, int start, int length) {
    buffer.append(ch, start, length);
}

public ArrayList<Movie> retrieveMovieList() {
    return movieList;
}
else if (localName.equals("budget")) {
    movie.trailer = buffer.toString();
}