1

I've set out some code for reading an OPML file for subscriptions from YouTube. The code comes from Informa RSS here

When I run the code I get class missing error. The only reference to this I could find suggested the javaDOM version might be wrong since it was updated to DOM2.0 but failed to tell me how I could fix, it just said to use an older one and gave a link to a javaDOM version 0.7?

Now when I installed the JavaDOM 0.7 into the Library for Netbeans the error disappears until I try to run or compile it and it fails....

Now I dont know where to go with it.

I've been struggling with this for a few days now, my main problem is the OPML file has all the same tag information, ie

<opml version="1.1">
<body>
    <outline text="YouTube Subscriptions" title="YouTube Subscriptions">
            <outline text="PersonOne" title="PersonOne" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UCuNfoe7ozooi0LZgp6JJS4A" />
            <outline text="PersonTwo" title="PersonTwo" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UCVErFSr-jdTa_QE4PPSkVJw" />
            <outline text="Person Three" title="Person Three" type="rss" xmlUrl="https://www.youtube.com/feeds/videos.xml?channel_id=UCittVr8imKanO_5KohzDbpg" />
        </outline>
    </body>
</opml>

..and there isn't enough information about how to handle this combination of tags in Java, Ive been searching for three days...

JackDaw
  • 21
  • 5

1 Answers1

0

I couldn't get Informa 0.7.0-alpha2 to read the subscriptions exported as an OPML file from YouTube. The OPML consists of one outline element that contains multiple outline child elements for each RSS subscription.

Informa's OPMLParser class only looked at outline elements inside the body element, which is how most OPML subscription lists are structured. It didn't look for child outline elements inside outline.

As an alternative solution, I used the Java XML parsing library XOM 1.12.10. Here's the code to read the OPML file that YouTube produces:

try {
    // create an XML builder
    Builder bob = new Builder();
    // build an XML document from the OPML file
    Document doc = bob.build(new File("subscription_manager.xml"));
    // get the root element
    Element opml = doc.getRootElement();
    // get root's body element
    Element body = opml.getFirstChildElement("body");
    // get body's outline element
    Element outline = body.getFirstChildElement("outline");
    // get outline's child outline elements
    Elements outlines = outline.getChildElements("outline");
    // loop through those elements
    for (int i = 0; i < outlines.size(); i++) {
        // display each RSS feed's URL
        System.out.println(outlines.get(i).getAttributeValue("xmlUrl"));
    }            
} catch (ParsingException | IOException ex) {
    System.out.println(ex.getMessage());
}

This code has these imports:

import java.io.File;
import java.io.IOException;
import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.Element;
import nu.xom.Elements;
import nu.xom.ParsingException;
rcade
  • 204
  • 1
  • 11