|
1 |
| -# jopl - A lightweight OPML parser |
| 1 | +# jopl - A lightweight pure Java OPML parser |
| 2 | + |
| 3 | +[](https://jitpack.io/#zouroboros/jopl) |
| 4 | + |
| 5 | +The Outline Processor Markup Language (OPML) is an XML based format that is |
| 6 | +commonly used in RSS/Atom feed readers for importing and exporting a list of |
| 7 | +feeds. The original specification can be found [here](http://dev.opml.org/). |
| 8 | + |
| 9 | +An OPML file consist of a header which contains metadata such as a title and |
| 10 | +a creation date. The actual content is contained in the body of an OPML file. |
| 11 | +The body of an OPML file is a list of several outlines each consisting of a |
| 12 | +title, text, type, http url, and a xml url. |
| 13 | + |
| 14 | +The jopl library provides a simple interface for reading and writing OPML files. |
| 15 | +Under the hood jopl uses the [xmlpull](http://www.xmlpull.org) API for working with |
| 16 | +XML files. This makes jopl particular suited for Android apps. You can use jopl as |
| 17 | +a maven package via [jitpack.io](https://jitpack.io/#zouroboros/jopl). |
| 18 | + |
| 19 | +In most cases the `Jopl` class provides a simple interface for reading and writing |
| 20 | +OPML files. |
| 21 | + |
| 22 | +The following snippet shows how to read an OPML file into an Outlines object. |
| 23 | +``` |
| 24 | +Reader reader = FileReader("example.opml"); |
| 25 | +Outlines outlines = Jopl.outlines(reader); |
| 26 | +``` |
| 27 | +The outlines object has getters which allow accessing the informations contained |
| 28 | +in the head and body sections. |
| 29 | +``` |
| 30 | +outlines.getTitle(); // the title of the OPML file. |
| 31 | +outlines.getDateCreated(); // returns the creation date of the OPML file. |
| 32 | +``` |
| 33 | + |
| 34 | +The list of outlines can be accessed via the `getOutlinesMethod`. |
| 35 | + |
| 36 | +``` |
| 37 | +List<OpOutlines> outlinesList = outlines.getOutlines(); |
| 38 | +``` |
| 39 | + |
| 40 | +Outlines can also be created from scratch. |
| 41 | +``` |
| 42 | +String title = "Outlines created via code"; |
| 43 | +Date creationDate = new Date(); |
| 44 | +List<OpOutline> outlinesList = new LinkedList<OpOutline>(); |
| 45 | +outlinesList.add(new OpOutline("Outline title", "Outline text", "outlinetype", |
| 46 | + "https://example.org/xmlUrl", "https://example.org/httpUrl")); |
| 47 | +Outlines outlines = new Outlines(title, creationDate, outlinesList); |
| 48 | +``` |
| 49 | + |
| 50 | +Existing `Outlines` objects can be written to files via the `write` methods in |
| 51 | +the `Jopl` class. |
| 52 | +``` |
| 53 | +FileOutputStream outputStream = new FileOutputStream("test.opml"); |
| 54 | +XmlSerializer xmlSerializer = ...; |
| 55 | +Outlines outlines = ...; |
| 56 | +Jopl.write(outlines, outputStream, xmlSerializer); |
| 57 | +``` |
0 commit comments