2016-09-23 5 views
0

のSimpleXMLデシリアライザ

@Root 
    public static class Book { 

     @ElementList(entry = "CHAPTER", inline = true) public ArrayList<ReceiptElement> chapter; 

     public ReceiptElement getChapterLines() { 
      if (this. chapter != null && this. chapter.size() > 0) 
       return chapter.get(0); 
      else 
       return null; 
     } 

    } 

    @Root 
    public static class Chapter { 

     @ElementList(entry = "TEXTLINE", inline = true) public ArrayList<TextLine> lines; 

     public ArrayList<TextLine> getLines() { 
      return this.lines; 
     } 


    } 

    public static class TextLine { 

     private String textline; 

     public TextLine(@ElementMap(entry = "TEXTLINE") String text) { 
      this.textline = text; 
     } 

     public String getTextline() { return this.textline; } 
    } 

私が手例外:

org.simplefrをamework.xml.core.ConstructorException:

私は運なしでいくつかのバリエーションを試してみましたTextLineパラメータは「」 はクラスで試合を持っていません。

ありがとうございます。

答えて

0

最初に解析する前に、XMLが有効かどうかを確認してください。ここでは、オンラインのXMLバリデータでチェックすることができます。http://www.xmlvalidation.com/
<CHAPTER>タグの間にスペースを削除してみてください<BOOK>

を終了し、私はあなたがTextLineクラスに@Rootを追加していないので、この例外org.simpleframework.xml.core.ConstructorException: Parameter '' does not have a match in class TextLineがあると思います。

<BOOK> 
    <CHAPTER> 
    <TEXTLINE/> 
    <TEXTLINE> line of text.... </TEXTLINE> 
    <TEXTLINE> line of text... </TEXTLINE> 
    </CHAPTER> 
    <CHAPTER> 
    <TEXTLINE/> 
    <TEXTLINE> line of text.... </TEXTLINE> 
    </CHAPTER> 
</BOOK> 

Book.java

@Root 
    public class Book { 
     @ElementList(entry = "CHAPTER", inline = true) public ArrayList<Chapter> chapter; 

     public Chapter getChapterLines() { 
      if (this. chapter != null && this. chapter.size() > 0) 
       return chapter.get(0); 
      else 
       return null; 
     } 
    } 

Chapter.java

@Root 
public class Chapter { 

    @ElementList(entry = "TEXTLINE", inline = true) public ArrayList<TextLine> lines; 

    public ArrayList<TextLine> getLines() { 
     return this.lines; 
    } 
} 

TextLine.java

@Root 
    public class TextLine { 

     private String textline; 

     public TextLine(@ElementMap(entry = "TEXTLINE") String text) { 
      this.textline = text; 
     } 
     public String getTextline() { return this.textline; } 
    } 
+0

XMLが有効で、空白が削除されましたが、変更は一切ありません。 – Marco

+0

あなたのコードには多くのエラーがあり、変更が加えられ、投稿されました。これを一度試してください。今すぐ使えることを願っています。 – Shaggy

+0

シャギー、ありがとう。しかし、私は@ROOTを試していて、どちらもうまく動作しませんでしたが、まだ問題はありますが、私は文字列クラスを使ってすぐに解析しましたが、なぜsimplexmlで動作していないのかを見たいと思っています – Marco