2015-10-18 102 views
0

我试图读取由excel生成的一些xml到Android。即时通讯使用Simplexml来做到这一点。android使用simplexml读取xml

即使将行列入列表,IM也遇到了麻烦。我得到的错误是... “org.simpleframework.xml.core.PersistenceException:元素'行'已与@ org.simpleframework.xml.ElementList一起使用”...

但我不知道为什么。任何想法为什么?

的XML看起来像这样...

<?xml version="1.0" encoding="UTF-8"?> 
<?mso-application progid="Excel.Sheet"?> 
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel"> 
    <Worksheet ss:Name="DDDDDDDDDDDDDD"> 
     <Table ss:ExpandedColumnCount="20" ss:ExpandedRowCount="2672" x:FullColumns="1" x:FullRows="1" ss:DefaultRowHeight="15"> 
     <Row> 
      <Cell> 
       <Data ss:Type="Number">123</Data> 
      </Cell> 
      <Cell ss:Index="4"> 
       <Data ss:Type="Number">4</Data> 
      </Cell> 
      <Cell ss:Index="6"> 
       <Data ss:Type="String">sdinmsd</Data> 
      </Cell> 
      <Cell ss:Index="9"> 
       <Data ss:Type="String">dsddf</Data> 
      </Cell> 
      <Cell ss:Index="11"> 
       <Data ss:Type="String">sdsdsd 1AB</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="String">S06Cvcvvc28048</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="String">Kdfdf</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="Number">1dfd</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="Number">835df</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="Number">102df</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="Number">393df</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="Number">2012dfdf1005</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="String">New Custdfdfomer</Data> 
      </Cell> 
     </Row> 
     <Row> 
      <Cell> 
       <Data ss:Type="Number">123</Data> 
      </Cell> 
      <Cell ss:Index="4"> 
       <Data ss:Type="Number">4</Data> 
      </Cell> 
      <Cell ss:Index="6"> 
       <Data ss:Type="String">sdinmsd</Data> 
      </Cell> 
      <Cell ss:Index="9"> 
       <Data ss:Type="String">dsddf</Data> 
      </Cell> 
      <Cell ss:Index="11"> 
       <Data ss:Type="String">sdsdsd 1AB</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="String">S06Cvcvvc28048</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="String">Kdfdf</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="Number">1dfd</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="Number">835df</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="Number">102df</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="Number">393df</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="Number">2012dfdf1005</Data> 
      </Cell> 
      <Cell> 
       <Data ss:Type="String">New Custdfdfomer</Data> 
      </Cell> 
     </Row> 
     </Table> 
    </Worksheet> 
</Workbook> 

和我解析的代码看起来像这样...

@Root(strict = false) 
public class LocksXmlDisplay { 

    @Element (name = "Worksheet") 
    private Worksheet worksheet; 

    public Worksheet getWorksheet() { 
     return worksheet; 
    } 


    @Root(strict = false) 
    public static class Worksheet { 
     @Element (name = "Table") 
     private Tables tables; 
     public Tables gettables() { 
      return tables; 
     } 

     @Root(strict = false) 
     public static class Tables { 

      @ElementList(name = "Row") 
      private List<Row> list; 
      public List getrows() { 
       return list; 
      } 

      @Root(strict = false) 
      public static class Row { 

      } 
     } 
    } 
} 

回答

0

你忘了指定的列表Tableinline=true

例如,

<?xml...> 
<Hello> 
    <World> 
     <Magic name="Friendship"/> 
     <Magic name="Love"/> 
     <Magic name="Devotion"/> 
     <Magic name="Miracle"/> 
    </World> 
</Hello> 

将要么

@Root(name="Hello") 
public class Hello { 
    @Element(name="World") 
    private World world; 

    //getter, setter 
} 

@Root(name="World") 
public class World { 
    @ElementList(type=Magic.class, inline=true) 
    private List<Magic> magics; 

    //getter, setter 
} 

@Root(name="Magic") 
public class Magic { 
    @Attribute(name="name") 
    private String name; 

    //getter, setter 
} 

@Root(name="Hello") 
public class Hello { 
    @ElementList(type=Magic.class, name="World", inline=false) 
    private List<Magic> world; 

    //getter, setter 
} 

@Root(name="Magic") 
public class Magic { 
    @Attribute(name="name") 
    private String name; 

    //getter, setter 
} 

此致是第一种情况,如在Table包含 inline list一个。