遇到一种xml格式的excel文件,格式大概如下:
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:o="urn:schemas-microsoft-com:office:office"
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">
 <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
  <Created>2009-12-18T14:44:09Z</Created>
  <Version>12.00</Version>
 </DocumentProperties>
 <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
  <WindowHeight>10005</WindowHeight>
  <WindowWidth>10005</WindowWidth>
  <WindowTopX>120</WindowTopX>
  <WindowTopY>135</WindowTopY>
  <ProtectStructure>False</ProtectStructure>
  <ProtectWindows>False</ProtectWindows>
 </ExcelWorkbook>
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Center"/>
   <Font ss:FontName="Verdana" x:Family="Swiss"/>
  </Style>
  <Style ss:ID="s62">
   <Font ss:FontName="Verdana" x:Family="Swiss"/>
  </Style>
  <Style ss:ID="s63">
   <Alignment ss:Horizontal="Center" ss:Vertical="Center"/>
   <Interior ss:Color="#C0C0C0" ss:Pattern="Solid"/>
  </Style>
 </Styles>
 <Worksheet ss:Name="Average">
  <Table ss:ExpandedColumnCount="5" ss:ExpandedRowCount="2" x:FullColumns="1"
   x:FullRows="1" ss:StyleID="s62" ss:DefaultColumnWidth="54">
   <Column ss:StyleID="s62" ss:AutoFitWidth="0" ss:Width="140.25"/>
   <Column ss:StyleID="s62" ss:AutoFitWidth="0" ss:Width="99.75" ss:Span="3"/>
   <Row>
    <Cell ss:StyleID="s63"><Data ss:Type="String">col1</Data></Cell>
    <Cell ss:StyleID="s63"><Data ss:Type="String">col2</Data></Cell>
    <Cell ss:StyleID="s63"><Data ss:Type="String">col3</Data></Cell>
    <Cell ss:StyleID="s63"><Data ss:Type="String">col4</Data></Cell>
   </Row>
   <Row>
    <Cell><Data ss:Type="Number">1</Data></Cell>
    <Cell><Data ss:Type="Number">2</Data></Cell>
    <Cell><Data ss:Type="Number">3</Data></Cell>
    <Cell><Data ss:Type="Number">4</Data></Cell>
   </Row>
  </Table>
 </Worksheet>
</Workbook>
想问一下除了直接用xml自己解释外有什么好的处理办法。

解决方案 »

  1.   

    帮忙顶了了,我解决不了。关注ing
      

  2.   

    xml你还要用什么来解释。。
    要么用dom
    要么用文本判断
      

  3.   

    用dom比较原始一些,我是想问下有没有其他更高级点的处理方法,
    像这种格式这么强的xml,有没有库可以像jxl,poi处理excel那样
    处理它。
      

  4.   

    xml的excel会有一个问题不知道楼主有没有遇到过,怎么解析合并单元格,我觉得还是使用api来读取excel比较稳妥
      

  5.   

    建议楼主看看Xstream ,或许对你有帮助,处理这种固定格式的xml下面是个小例子:
    官方网站:http://xstream.codehaus.org/
    XStream是一套用java编写的开源工具库
    目的在于将java对象串行化为xml和将xml反向串行化为java对象首先定义两个类
    public class Person { 
        private String firstname; 
        private String lastname; 
        private PhoneNumber phone; 
        private PhoneNumber fax; 
        // ... constructors and methods 

    public class PhoneNumber { 
        private int code; 
        private String number;
    // ... constructors and methods 

    注:
    XStream对于对象类的结构不做限制
    1.类属性的可见度可以任意(public private protected)
    2.不要求必须有get和set方法
    3.不要求必须有缺省的构造函数使用XStream
    XStream xstream = new XStream();
    需要将xstream-[version].jar和xpp3-[version].jar加到classpath,xpp3是一个快速的xml解析器
    xpp3.jar并不是必须的,我们可以使用标准的JAXP DOM 解析器
    XStream xstream = new XStream(new DomDriver());
    XStream有多个构造函数,我们可以定义更加灵活的XStream实例
    Person joe = new Person("Joe", "Walnes"); 
    joe.setPhone(new PhoneNumber(123, "1234-456"));
    joe.setFax(new PhoneNumber(123, "9999-999")); 
    String xml = xstream.toXML(joe);
    这样就完成了对象到xml的串行化 结果如下:
    <com.thoughtworks.xstream.person>
      <firstname>Joe</firstname> 
      <lastname>Walnes</lastname> 
      <phone> 
      <code>123</code> 
      <number>1234-456</number> 
      </phone> 
      <fax> 
      <code>123</code> 
      <number>9999-999</number>
      </fax> 
    </com.thoughtworks.xstream.person> 
    xml到java对象的反串行化
    Person newJoe = (Person)xstream.fromXML(xml);

      

  6.   

    xmlns:o="urn:schemas-microsoft-com:office:office"
     xmlns:x="urn:schemas-microsoft-com:office:excel"
     xmlns:ss="urn:chinese wholesalers
    ugg-microsoft-com:office:spreadsheet"
     xmlns:html="http://www.w3.org/TR/REC-html40"
      

  7.   

    没办法,直接解析。看你的好像也不能用xstream。