I'm currently working on a project which implies XML feed parsing (Atom 2005) and I'm using Rome to do this.
I have currently two kind of XML structure to parse.
The first type :
<?xml version="1.0" encoding="UTF-8"?>
<feed
xmlns="http://www.w3.org/2005/Atom"
xml:base="..." >
<id>...</id>
<title type="text" >...</title>
<entry xmlns="http://www.w3.org/2005/Atom" >
<id>...</id>
</entry>
<entry xmlns="http://www.w3.org/2005/Atom" >
<id>...</id>
</entry>
...
</feed>
(One feed, containing several entries)
The second type :
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" >
<id>...</id>
</entry>
(One entry, but it is not contained in a "feed")
My objective is to make a bean "MyEntry" which parse input XML and get information. My ideal would be to have ONE constructor (which takes an SyndEntry as argument for example).
I did that :
public MyEntry( SyndEntry e ) {
_entry = e;
}
I can get "SyndEntry" objects when I get first type of XML feed :
SyndFeedInput feed_input = new SyndFeedInput();
...
SyndFeed feed = feed_input.build(xml_file);
for ( SyndEntry e : feed.getEntries() ) {
// I can get SyndEntries from here
}
--> But with the second type of XML, there is not "feed" container and I can't find any method to build SyndEntry from XML directly (like a "SyndEntryInput" ?). I get a "SyndFeed" instead of a "SyndEntry", even if all information remains accessible.
Thus, I'm looking for a way to convert SyndFeed to SyndEntry (or reverse), using a superclass (I can't find any superclass common to SyndEntry and SyndFeed) or a dedicated converter.
My current solution is to make two constructors (one taking "SyndFeed", and other one taking "SyndEntry"), but it's quite ugly because I've a method "getSyndData()" which ideally returns object used for construction, usefull for retrieving generic info (ie: getSyndData().getTitle())
Any help or idea would be appreciated