I set myself the task of being able to parse a random xml file generated
by Excel 2003 and I'm having odd problems which I can't really
understand.
---- Question Setup ----
Excel defines two element each with their own namespace. I'll paste the
XML file at the bottom of this message.
** notice the top two elements: <DocumentPorperties> and <ExcelWorkbook>
When those two elements with their namespaces atrributes are present, I
can't access any of the lower elements like <Styles> or <Worksheet>,
When I manually delete the namespace attributes, everything works fine.
In other words:
@doc.root.elements.each('Worksheet') {} retruns three elements when I
remove the namespace attribute, but nothing when I put it back in.
---- Actual Question ---
Is this just a weird instance of XML which REXML doesn't support or do I
need to be doing some fancy XPath footwork to make it work?
cheers and thanks! :)
Andrew
----- Sample Excel file -----
<?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">
<Author>Gibson, Andrew</Author>
<LastAuthor>agibson</LastAuthor>
<Created>2006-06-26T12:48:00Z</Created>
<LastSaved>2006-06-26T12:50:55Z</LastSaved>
<Company></Company>
<Version>11.6360</Version>
</DocumentProperties>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>8835</WindowHeight>
<WindowWidth>15180</WindowWidth>
<WindowTopX>120</WindowTopX>
<WindowTopY>105</WindowTopY>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom"/>
<Borders/>
<Font/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
</Styles>
<Worksheet ss:Name="Book1">
<Table ss:ExpandedColumnCount="3" ss:ExpandedRowCount="17"
x:FullColumns="1"
x:FullRows="1">
<Column ss:AutoFitWidth="0" ss:Width="86.25"/>
<Column ss:AutoFitWidth="0" ss:Width="71.25"/>
<Column ss:AutoFitWidth="0" ss:Width="96"/>
<Row>
<Cell><Data ss:Type="String">Column1</Data></Cell>
<Cell><Data ss:Type="String">Column2</Data></Cell>
<Cell><Data ss:Type="String">Column3</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>
</Row>
<Row>
<Cell><Data ss:Type="Number">4</Data></Cell>
<Cell><Data ss:Type="Number">5</Data></Cell>
<Cell><Data ss:Type="Number">6</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">7</Data></Cell>
<Cell><Data ss:Type="Number">8</Data></Cell>
<Cell><Data ss:Type="Number">9</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">10</Data></Cell>
<Cell><Data ss:Type="Number">11</Data></Cell>
<Cell><Data ss:Type="Number">12</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">13</Data></Cell>
<Cell><Data ss:Type="Number">14</Data></Cell>
<Cell><Data ss:Type="Number">15</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">16</Data></Cell>
<Cell><Data ss:Type="Number">17</Data></Cell>
<Cell><Data ss:Type="Number">18</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">19</Data></Cell>
<Cell><Data ss:Type="Number">20</Data></Cell>
<Cell><Data ss:Type="Number">21</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">22</Data></Cell>
<Cell><Data ss:Type="Number">23</Data></Cell>
<Cell><Data ss:Type="Number">24</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">25</Data></Cell>
<Cell><Data ss:Type="Number">26</Data></Cell>
<Cell><Data ss:Type="Number">27</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">28</Data></Cell>
<Cell><Data ss:Type="Number">29</Data></Cell>
<Cell><Data ss:Type="Number">30</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">31</Data></Cell>
<Cell><Data ss:Type="Number">32</Data></Cell>
<Cell><Data ss:Type="Number">33</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">34</Data></Cell>
<Cell><Data ss:Type="Number">35</Data></Cell>
<Cell><Data ss:Type="Number">36</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">37</Data></Cell>
<Cell><Data ss:Type="Number">38</Data></Cell>
<Cell><Data ss:Type="Number">39</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">40</Data></Cell>
<Cell><Data ss:Type="Number">41</Data></Cell>
<Cell><Data ss:Type="Number">42</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">43</Data></Cell>
<Cell><Data ss:Type="Number">44</Data></Cell>
<Cell><Data ss:Type="Number">45</Data></Cell>
</Row>
<Row>
<Cell><Data ss:Type="Number">46</Data></Cell>
<Cell><Data ss:Type="Number">47</Data></Cell>
<Cell><Data ss:Type="Number">48</Data></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<Selected/>
<Panes>
<Pane>
<Number>3</Number>
<ActiveRow>17</ActiveRow>
<ActiveCol>4</ActiveCol>
</Pane>
</Panes>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Sheet2">
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Sheet3">
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
-----------------------------------------------
--
Posted via http://www.ruby-forum.com/.