2012-11-09 6 views
2

저는 SimpleXML 라이브러리로 작업하고 있습니다. RSS 피드를 가져 와서 자바 객체로 변환해야합니다.SimpleXML 문제

@Root 
public class RssType { 

    @Element(name="channel") 
    private ChannelType channel; 

    @Attribute 
    private String version; 

    public ChannelType getChannel() { 
     return channel; 
    } 

    public void setChannel(ChannelType channel) { 
     this.channel = channel; 
    } 

    public String getVersion() { 
     return version; 
    } 

    public void setVersion(String version) { 
     this.version = version; 
    } 


} 



@Element(name="channel") 
public class ChannelType { 

    @Element 
    private String title; 

    @Element 
    private String link; 

    @Element 
    private String description; 

    @Element 
    private String lastBuildDate; 

    @Element 
    private String generator; 

    @Element 
    @Namespace(reference="http://www.livejournal.org/rss/lj/1.0/", prefix="lj") 
    private String journal; 

    @Element 
    @Namespace(reference="http://www.livejournal.org/rss/lj/1.0/", prefix="lj") 
    private String journalid; 

    @Element 
    @Namespace(reference="http://www.livejournal.org/rss/lj/1.0/", prefix="lj") 
    private String journaltype; 

    @Element 
    private ImageType image; 

    @ElementList(inline=false) 
    private List<ItemType> item; 

    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 

    public String getLink() { 
     return link; 
    } 

    public void setLink(String link) { 
     this.link = link; 
    } 

    public String getDescription() { 
     return description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 

    public String getLastBuildDate() { 
     return lastBuildDate; 
    } 

    public void setLastBuildDate(String lastBuildDate) { 
     this.lastBuildDate = lastBuildDate; 
    } 

    public String getGenerator() { 
     return generator; 
    } 

    public void setGenerator(String generator) { 
     this.generator = generator; 
    } 

    public String getJournal() { 
     return journal; 
    } 

    public void setJournal(String journal) { 
     this.journal = journal; 
    } 

    public String getJournalid() { 
     return journalid; 
    } 

    public void setJournalid(String journalid) { 
     this.journalid = journalid; 
    } 

    public String getJournaltype() { 
     return journaltype; 
    } 

    public void setJournaltype(String journaltype) { 
     this.journaltype = journaltype; 
    } 

    public ImageType getImage() { 
     return image; 
    } 

    public void setImage(ImageType image) { 
     this.image = image; 
    } 

    public List<ItemType> getItem() { 
     return item; 
    } 

    public void setItem(List<ItemType> item) { 
     this.item = item; 
    } 


} 


@Element(name="image") 
public class ImageType { 

    @Element 
    private String url; 

    @Element 
    private String title; 

    @Element 
    private String link; 

    @Element 
    private String width; 

    @Element 
    private String height; 


    public String getUrl() { 
     return url; 
    } 

    public void setUrl(String url) { 
     this.url = url; 
    } 

    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 

    public String getLink() { 
     return link; 
    } 

    public void setLink(String link) { 
     this.link = link; 
    } 

    public String getWidth() { 
     return width; 
    } 

    public void setWidth(String width) { 
     this.width = width; 
    } 

    public String getHeight() { 
     return height; 
    } 

    public void setHeight(String height) { 
     this.height = height; 
    } 


} 


@Element(name="item") 
public class ItemType { 

    @Element 
    private GuidType guid; 

    @Element 
    private String pubDate; 

    @Element 
    private String title; 

    @Element 
    private String link; 

    @Element 
    private String description; 

    @Element 
    private String comments; 

    @ElementList(inline=false) 
    private List<String> category; 

    @Element 
    @Namespace(reference="http://www.livejournal.org/rss/lj/1.0/", prefix="lj") 
    private String security; 

    @Element 
    @Namespace(reference="http://www.livejournal.org/rss/lj/1.0/", prefix="lj") 
    private String replyCount; 

    public GuidType getGuid() { 
     return guid; 
    } 

    public void setGuid(GuidType guid) { 
     this.guid = guid; 
    } 

    public String getPubDate() { 
     return pubDate; 
    } 

    public void setPubDate(String pubDate) { 
     this.pubDate = pubDate; 
    } 

    public String getTitle() { 
     return title; 
    } 

    public void setTitle(String title) { 
     this.title = title; 
    } 

    public String getLink() { 
     return link; 
    } 

    public void setLink(String link) { 
     this.link = link; 
    } 

    public String getDescription() { 
     return description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 

    public String getComments() { 
     return comments; 
    } 

    public void setComments(String comments) { 
     this.comments = comments; 
    } 


    public List<String> getCategory() { 
     return category; 
    } 

    public void setCategory(List<String> category) { 
     this.category = category; 
    } 

    public String getSecurity() { 
     return security; 
    } 

    public void setSecurity(String security) { 
     this.security = security; 
    } 

    public String getReplyCount() { 
     return replyCount; 
    } 

    public void setReplyCount(String replyCount) { 
     this.replyCount = replyCount; 
    } 


} 



@Element(name="guid") 
public class GuidType { 

    @Attribute 
    public String isPermaLink;  

    public String text; 

    @Text 
    public String getText() { 
     return text; 
    } 

    @Text 
    public void setText(String text) { 
     this.text = text; 
    } 

    public String getIsPermaLink() { 
     return isPermaLink; 
    } 

    public void setIsPermaLink(String isPermaLink) { 
     this.isPermaLink = isPermaLink; 
    } 


} 

이 코드 실행 : 다음은 XML은 내가 정의한 객체에

<rss xmlns:lj="http://www.livejournal.org/rss/lj/1.0/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:atom10="http://www.w3.org/2005/Atom" version="2.0"> 
<channel> 
<title>Всегда! Везде! Со всеми! и ни с кем!</title> 
<link>http://xuma.livejournal.com/</link> 
<description> 
Всегда! Везде! Со всеми! и ни с кем! - LiveJournal.com 
</description> 
<lastBuildDate>Thu, 17 Mar 2011 10:08:33 GMT</lastBuildDate> 
<generator>LiveJournal/LiveJournal.com</generator> 
<lj:journal>xuma</lj:journal> 
<lj:journalid>5295048</lj:journalid> 
<lj:journaltype>personal</lj:journaltype> 
<copyright>NOINDEX</copyright> 
<image> 
<url>http://l-userpic.livejournal.com/104864030/5295048</url> 
<title>Всегда! Везде! Со всеми! и ни с кем!</title> 
<link>http://xuma.livejournal.com/</link> 
<width>66</width> 
<height>100</height> 
</image> 
<item> 
<guid isPermaLink="true">http://xuma.livejournal.com/7831.html</guid> 
<pubDate>Thu, 17 Mar 2011 10:08:33 GMT</pubDate> 
<title>Япония. Поможем пострадавшим.</title> 
<link>http://xuma.livejournal.com/7831.html</link> 
<description>...</description> 
<comments>http://xuma.livejournal.com/7831.html</comments> 
<lj:security>public</lj:security> 
<lj:reply-count>0</lj:reply-count> 
</item> 
<item> 
<guid isPermaLink="true">http://xuma.livejournal.com/7575.html</guid> 
<pubDate>Sat, 16 Oct 2010 12:36:48 GMT</pubDate> 
<link>http://xuma.livejournal.com/7575.html</link> 
<description> 
<h1>Тест личности</h1><br /><a href="http://teh-nomad.livejournal.com/667478.html"><img border="0" src="http://www.ljplus.ru/img4/a/s/astro_nomad/chtree_6.jpg" alt="" /></a><br /><br /><a href="http://teh-nomad.livejournal.com/667478.html">Выбрать себе дерево</a> 
</description> 
<comments>http://xuma.livejournal.com/7575.html</comments> 
<lj:music>I chase the Devil</lj:music> 
<media:title type="plain">I chase the Devil</media:title> 
<lj:mood>опаздываю...</lj:mood> 
<lj:security>public</lj:security> 
<lj:reply-count>0</lj:reply-count> 
</item> 
</channel> 
</rss> 
다음

있는 콩을 매핑 할 필요가

String xmlData = retrieve("http://zuma.livejournal.com/data/rss"); 

     Serializer serializer = new Persister();    

     RssType example = serializer.read(RssType.class, xmlData); 

얻기과 같은 예외를

org.simpleframework.xml.core.AttributeException: Attribute 'isPermaLink' does not have a match in class com.ljclient.xml.beans.ItemType at line 22 

하지만 isPermaLink<item> 노드의 속성이 아니고 <guid> 노드의 속성입니다.

나는 <item>의 속성으로 isPermaLink 한 경우 그 경우 나는 예외 다음 받고 있어요 :

값이 각 카테고리의 노드에 존재하기 때문에
org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(data=false, empty=true, entry=, inline=false, name=, required=true, type=void) on field 'category' private java.util.List com.ljclient.xml.beans.ItemType.category for class com.ljclient.xml.beans.ItemType at line 22 

그 이상한. 어떤 아이디어?

답변

5

이 질문에 대한 직접적인 대답은 아니지만 RssType 인스턴스를 만들고 XML에 쓰려 고 시도해 보았습니다. 이 실습의 요점은 명백한 문제에 대해 마크 업이 XML로 변환되는 방식을 확인할 수 있다는 것입니다.

public static void main(String[] args) { 
    RssType rss = new RssType(); 
    rss.setVersion("1.0"); 
    ChannelType channel = new ChannelType(); 
    channel.setTitle("Test title"); 
    // Set the rest of the variables 
    rss.setChannel(channel); 

    //do the same for you other types then 
    //convert it to xml 

    Serializer serializer = new Persister(); 
    File result = new File("rss.xml"); 

    serializer.write(rss, result); 
} 

이 문제는 즉시 해결되지는 않지만 문제가 무엇인지 식별해야합니다.

public static void main(String[] args) throws Exception { 
    ItemType item = new ItemType(); 

    GuidType guid = new GuidType(); 
    guid.setIsPermaLink("true"); 
    guid.setText("http://zuma.livejournal.com/147000.html");  
    item.setGuid(guid); 
    item.setPubDate("Sun, 07 Oct 2012 06:43:24 GMT"); 
    item.setTitle("tao machine"); 
    item.setLink("http://zuma.livejournal.com/147000.html"); 
    item.setDescription(">&lt;div class=&quot;qpp3&quot;&gt;&lt;div class=&quot;qpp4&quot;&gt;&lt;div class=&quot;qrbrdr1&quot;&gt;&lt;div class=&quot;qrbrdr2&quot;&gt;&lt;center&gt;&lt;img src=&quot;http://zuma.vip.warped.com/transparent_8x8.png&quot;&gt;&lt;br&gt;&lt;a title=&quot;http://stonedmotors.blogspot.com/2012/10/tao-machine.html&quot; href=&quot;http://stonedmotors.blogspot.com/2012/10/tao-machine.html&quot;&gt;&lt;img src=&quot;http://zuma.vip.warped.com/stonedmotors2.png&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;br&gt;&lt;img src=&quot;http://zuma.vip.warped.com/transparent_8x8.png&quot;&gt;&lt;/center&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src=&quot;http://zuma.vip.warped.com/transparent_8x8.png&quot;&gt;&lt;br&gt;&lt;div class=&quot;a720&quot;&gt;&lt;div class=&quot;b720&quot;&gt;&lt;span class=&quot;tnr&quot;&gt;midnight&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&quot;dirt-tired, greased &amp; wired, but the job&apos;s done, hey.&quot;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;the scattered tools upon the table, all in disarray. the wrenches, sockets, screwdrivers, extensions &amp; adaptors, nuts &amp; bolts &amp; washers scrounged from the floor and about all (mostly) gathered in coffee cans... the piles of parts; case halves, studs, con rods &amp; cranks, camshafts &amp; shims, heads, manifolds, oil radiators, fan housings, distributors, coils, voltage regulators, generators &amp; alternators, carbs &amp; pistons, fuel pumps, filters, trannies, CV joints, axles, brake shoes, fuses, spark plugs, batteries, mufflers, belts, pulleys, flywheels... the cans of mineral spirits, carb cleaner, oil &amp; gas; brake fluid... cleaning a set of wheel bearings w/ an air hose sets it spinning at umpteen hundred RPM. buckets of grease. pressure plates &amp; throw-out bearings. clamps &amp; hoses. breaker bars &amp; torgue wrenches. plastigauge. pedal clusters. cables. shifter plates &amp; bushings. tires, wheels, brake drums clanging, struck by a 5 pound sledge hammer. smoke from the ashtray curls up to the rafters. the coffee pot ticks. we laugh like mad children w/ dirt (like black soot) on our faces &amp; elbows &amp; old worn clothing in the midnight garage.&lt;/div&gt;&lt;/div&gt;&lt;img src=&quot;http://zuma.vip.warped.com/transparent_8x8.png&quot;&gt;&lt;div class=&quot;zim&quot;&gt;&lt;div class=&quot;im1&quot;&gt;&lt;div class=&quot;im2&quot;&gt;&lt;a title=&quot;960x640 version&quot; href=&quot;http://zuma.vip.warped.com/stomo8.png&quot;&gt;&lt;img src=&quot;http://zuma.vip.warped.com/stomo8_716x476.png&quot; border=&quot;0&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;img src=&quot;http://zuma.vip.warped.com/transparent_8x8.png&quot;&gt;&lt;div class=&quot;a720&quot;&gt;&lt;div class=&quot;b720&quot;&gt;the eternal engine that moves us. forward.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&quot;i could carve one from a rock...&quot;&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;crank it over. snick it in gear. let out the clutch. foot on the gas in Wide Open Throttle.&lt;br /&gt;&lt;br /&gt;stand on it.&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;"); 
    item.setComments("http://zuma.livejournal.com/147000.html"); 
    item.setSecurity("public"); 
    item.setReplyCount("8"); 
    item.setCategory(new ArrayList<String>()); 

    Serializer serializer = new Persister(); 
    File result = new File("rss.xml"); 

    serializer.write(item, result); 
} 

을 그리고있어 :


좋아 난 그냥 시도

<itemType> 
    <guid isPermaLink="true">http://zuma.livejournal.com/147000.html</guid> 
    <pubDate>Sun, 07 Oct 2012 06:43:24 GMT</pubDate> 
    <title>tao machine</title> 
    <link>http://zuma.livejournal.com/147000.html</link> 
    <description>&gt;&amp;lt;div class=&amp;quot;qpp3&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;qpp4&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;qrbrdr1&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;qrbrdr2&amp;quot;&amp;gt;&amp;lt;center&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/transparent_8x8.png&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&amp;lt;a title=&amp;quot;http://stonedmotors.blogspot.com/2012/10/tao-machine.html&amp;quot; href=&amp;quot;http://stonedmotors.blogspot.com/2012/10/tao-machine.html&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/stonedmotors2.png&amp;quot; border=&amp;quot;0&amp;quot;&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/transparent_8x8.png&amp;quot;&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/transparent_8x8.png&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&amp;lt;div class=&amp;quot;a720&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;b720&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;tnr&amp;quot;&amp;gt;midnight&amp;lt;/span&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;i&amp;gt;&amp;quot;dirt-tired, greased &amp;amp; wired, but the job&amp;apos;s done, hey.&amp;quot;&amp;lt;/i&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;the scattered tools upon the table, all in disarray. the wrenches, sockets, screwdrivers, extensions &amp;amp; adaptors, nuts &amp;amp; bolts &amp;amp; washers scrounged from the floor and about all (mostly) gathered in coffee cans... the piles of parts; case halves, studs, con rods &amp;amp; cranks, camshafts &amp;amp; shims, heads, manifolds, oil radiators, fan housings, distributors, coils, voltage regulators, generators &amp;amp; alternators, carbs &amp;amp; pistons, fuel pumps, filters, trannies, CV joints, axles, brake shoes, fuses, spark plugs, batteries, mufflers, belts, pulleys, flywheels... the cans of mineral spirits, carb cleaner, oil &amp;amp; gas; brake fluid... cleaning a set of wheel bearings w/ an air hose sets it spinning at umpteen hundred RPM. buckets of grease. pressure plates &amp;amp; throw-out bearings. clamps &amp;amp; hoses. breaker bars &amp;amp; torgue wrenches. plastigauge. pedal clusters. cables. shifter plates &amp;amp; bushings. tires, wheels, brake drums clanging, struck by a 5 pound sledge hammer. smoke from the ashtray curls up to the rafters. the coffee pot ticks. we laugh like mad children w/ dirt (like black soot) on our faces &amp;amp; elbows &amp;amp; old worn clothing in the midnight garage.&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/transparent_8x8.png&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;zim&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;im1&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;im2&amp;quot;&amp;gt;&amp;lt;a title=&amp;quot;960x640 version&amp;quot; href=&amp;quot;http://zuma.vip.warped.com/stomo8.png&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/stomo8_716x476.png&amp;quot; border=&amp;quot;0&amp;quot;&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/transparent_8x8.png&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;a720&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;b720&amp;quot;&amp;gt;the eternal engine that moves us. forward.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;i&amp;gt;&amp;quot;i could carve one from a rock...&amp;quot;&amp;lt;/i&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;crank it over. snick it in gear. let out the clutch. foot on the gas in Wide Open Throttle.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;stand on it.&amp;lt;br /&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;</description> 
    <comments>http://zuma.livejournal.com/147000.html</comments> 
    <category class="java.util.ArrayList"/> 
    <lj:security xmlns:lj="http://www.livejournal.org/rss/lj/1.0/">public</lj:security> 
    <lj:replyCount xmlns:lj="http://www.livejournal.org/rss/lj/1.0/">8</lj:replyCount> 
</itemType> 

내가 필드가 설정되어 있지 않은 경우, 나는 점점 제외 된 것으로 나타났습니다. 그래서 나는 모든 것을 설정합니다. 그런 다음 XML을 다음과 같이 편집했습니다.

<itemType> 
    <guid isPermaLink="true">http://zuma.livejournal.com/147000.html</guid> 
    <pubDate>Sun, 07 Oct 2012 06:43:24 GMT</pubDate> 
    <title>tao machine</title> 
    <link>http://zuma.livejournal.com/147000.html</link> 
    <description>&gt;&amp;lt;div class=&amp;quot;qpp3&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;qpp4&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;qrbrdr1&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;qrbrdr2&amp;quot;&amp;gt;&amp;lt;center&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/transparent_8x8.png&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&amp;lt;a title=&amp;quot;http://stonedmotors.blogspot.com/2012/10/tao-machine.html&amp;quot; href=&amp;quot;http://stonedmotors.blogspot.com/2012/10/tao-machine.html&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/stonedmotors2.png&amp;quot; border=&amp;quot;0&amp;quot;&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;br&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/transparent_8x8.png&amp;quot;&amp;gt;&amp;lt;/center&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/transparent_8x8.png&amp;quot;&amp;gt;&amp;lt;br&amp;gt;&amp;lt;div class=&amp;quot;a720&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;b720&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;tnr&amp;quot;&amp;gt;midnight&amp;lt;/span&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;i&amp;gt;&amp;quot;dirt-tired, greased &amp;amp; wired, but the job&amp;apos;s done, hey.&amp;quot;&amp;lt;/i&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;the scattered tools upon the table, all in disarray. the wrenches, sockets, screwdrivers, extensions &amp;amp; adaptors, nuts &amp;amp; bolts &amp;amp; washers scrounged from the floor and about all (mostly) gathered in coffee cans... the piles of parts; case halves, studs, con rods &amp;amp; cranks, camshafts &amp;amp; shims, heads, manifolds, oil radiators, fan housings, distributors, coils, voltage regulators, generators &amp;amp; alternators, carbs &amp;amp; pistons, fuel pumps, filters, trannies, CV joints, axles, brake shoes, fuses, spark plugs, batteries, mufflers, belts, pulleys, flywheels... the cans of mineral spirits, carb cleaner, oil &amp;amp; gas; brake fluid... cleaning a set of wheel bearings w/ an air hose sets it spinning at umpteen hundred RPM. buckets of grease. pressure plates &amp;amp; throw-out bearings. clamps &amp;amp; hoses. breaker bars &amp;amp; torgue wrenches. plastigauge. pedal clusters. cables. shifter plates &amp;amp; bushings. tires, wheels, brake drums clanging, struck by a 5 pound sledge hammer. smoke from the ashtray curls up to the rafters. the coffee pot ticks. we laugh like mad children w/ dirt (like black soot) on our faces &amp;amp; elbows &amp;amp; old worn clothing in the midnight garage.&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/transparent_8x8.png&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;zim&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;im1&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;im2&amp;quot;&amp;gt;&amp;lt;a title=&amp;quot;960x640 version&amp;quot; href=&amp;quot;http://zuma.vip.warped.com/stomo8.png&amp;quot;&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/stomo8_716x476.png&amp;quot; border=&amp;quot;0&amp;quot;&amp;gt;&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;img src=&amp;quot;http://zuma.vip.warped.com/transparent_8x8.png&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;a720&amp;quot;&amp;gt;&amp;lt;div class=&amp;quot;b720&amp;quot;&amp;gt;the eternal engine that moves us. forward.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;i&amp;gt;&amp;quot;i could carve one from a rock...&amp;quot;&amp;lt;/i&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;crank it over. snick it in gear. let out the clutch. foot on the gas in Wide Open Throttle.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;stand on it.&amp;lt;br /&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;</description> 
    <comments>http://zuma.livejournal.com/147000.html</comments> 
    <lj:security xmlns:lj="http://www.livejournal.org/rss/lj/1.0/">public</lj:security> 
    <lj:replyCount xmlns:lj="http://www.livejournal.org/rss/lj/1.0/">8</lj:replyCount> 
</itemType> 

ChannelType 값을 제거했습니다. 내가하고 그것을 다시 읽으려고 할 때 :

ItemType read = serializer.read(ItemType.class, new File("rss.xml")); 

를 내가 얻을 :

Exception in thread "main" org.simpleframework.xml.core.ValueRequiredException: Unable to satisfy @org.simpleframework.xml.ElementList(entry=, name=, inline=false, data=false, empty=true, type=void, required=true) on field 'category' private java.util.List ItemType.category for class ItemType at line 1 
    at org.simpleframework.xml.core.Composite.validate(Composite.java:644) 
    at org.simpleframework.xml.core.Composite.readElements(Composite.java:449) 
    at org.simpleframework.xml.core.Composite.access$400(Composite.java:59) 
    at org.simpleframework.xml.core.Composite$Builder.read(Composite.java:1383) 
    at org.simpleframework.xml.core.Composite.read(Composite.java:201) 
    at org.simpleframework.xml.core.Composite.read(Composite.java:148) 
    at org.simpleframework.xml.core.Traverser.read(Traverser.java:92) 
    at org.simpleframework.xml.core.Persister.read(Persister.java:625) 
    at org.simpleframework.xml.core.Persister.read(Persister.java:606) 
    at org.simpleframework.xml.core.Persister.read(Persister.java:584) 
    at org.simpleframework.xml.core.Persister.read(Persister.java:543) 
    at org.simpleframework.xml.core.Persister.read(Persister.java:521) 
    at org.simpleframework.xml.core.Persister.read(Persister.java:426) 
    at Test.main(Test.java:31) 

을 그래서 기본적으로는 거기에있을 모든 필드를 필요로한다. 따라서 선택 입력란에서 @Element@ElementList(inline=false) 특수 효과를 @Element(required=false)@ElementList(inline=false, required=false)으로 변경해야합니다.

+0

감사합니다. 시도해 보겠습니다. – Demoniac18

+0

@ Demoniac18 편집을 참조하십시오. –