XML problem in Java

 
  • XML problem in Java

    Now I'm using the Java bindings that are linked on the API site.

    My project involves using a SOM network to find similar artists and tags. To train the network, I have to collect fairly large amounts of data from last.fm. I already got the top 2500 artists and saved them, so I don't have to bother the server every time, and now I'd like to get the first page of top tags for every artist and save that too. The problem is, when I get to the 255th artist on the list, Java throws the following exception:

    [Fatal Error] :274:9: XML document structures must start and end within the same entity. Exception in thread "main" de.umass.lastfm.CallException: org.xml.sax.SAXParseException: XML document structures must start and end within the same entity. at de.umass.lastfm.Caller.call(Caller.java:267) at de.umass.lastfm.Caller.call(Caller.java:163) at de.umass.lastfm.Caller.call(Caller.java:159) at de.umass.lastfm.Artist.getTopTags(Artist.java:197) at DataCollector.fetchTags(DataCollector.java:61) at DataCollector.main(DataCollector.java:101) Caused by: org.xml.sax.SAXParseException: XML document structures must start and end within the same entity. at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source) at de.umass.lastfm.Caller.call(Caller.java:247) ... 5 more

    Where DataCollector is the class I coded, and everything else is either a java built-in feature or hails from the jar file I downloaded for handling last.fm queries. Anyone got any idea how to fix that? It happens at the 255th artist mark every single time. I tried slowing down the queries (I thought maybe the server cuts me off because the querying goes too fast), to no avail.

  • And of course the method that's causing the exception.

    public void fetchTags() throws Exception{
    int i=0;
    BufferedWriter bw = new BufferedWriter(new FileWriter(new File("tags.txt")));
    for (String artist: artists){
    System.out.println(i);
    i++;
    bw = new BufferedWriter(new FileWriter(new File("tags"+i+".txt")));
    bw.write(artist+":");
    bw.newLine();
    Collection<Tag> tag = Artist.getTopTags(artist, key);
    for (Tag t: tag){
    tags.get(artists.indexOf(artist)).add(t.getName());
    bw.write(t.getName());
    bw.newLine();
    }
    Thread.sleep(500);
    }
    }

    • tburny sa...
    • Forum Moderator
    • 9 maj 2012, 22:13
    Can you post the XML?

    Combo.fm: Combine your favourite radio stations! | My Blog | scala-lastfmapi | Cache2k - A high performance Java in-memory cache
    P.S.: Do not click here
    throw new PokemonException(); //Gotta catch 'em all
    My forum post reflects my personal opinion :)
Anonyma användare kan inte skriva inlägg. Vänligen logga in eller skapa ett konto för att göra inlägg i forumen.