From: "Procházka Lukáš Ing. - Pontex s. r. o." <LPr@pontex.cz>
To: ConTeXt <ntg-context@ntg.nl>
Subject: XML and Lua/Ctx
Date: Wed, 14 Nov 2012 16:45:27 +0100 [thread overview]
Message-ID: <op.wnrsp1w1tpjj8f@lpr> (raw)
[-- Attachment #1: Type: text/plain, Size: 1506 bytes --]
Hello,
I've read that when Ctx is to process a XML file, the whole XML tree is loaded first and processed as wanted.
I'd need to process a XML file which represents an Excel workbook saved as .xml.
When working in pure Lua, I'm using Expat library (http://matthewwild.co.uk/projects/luaexpat/index.html) which allow to create a parser with callbacks (e.g. StartElement(), StopElement(), CharacterData()...).
It processes the .xml file on-the-go.
However, this solution cannot be used with Ctx as it causes Ctx to crash.
How to access a XML file loaded and parsed from within Ctx via Lua?
I attach a simple Excel XML (for those who are familiar with Excel and don't refuse using it).
As an example, I'd need process the attached .xml into a simple Lua table:
----
-- return -- Lua table as a result
{ workbooks =
{ [1] = { name = "1",
-- No more info is necessary so far,
-- I just need to see the way how to access XML elements
},
[2] = { name = "Imp",
},
[3] = { name = "Exp",
},
[4] = { name = "<Template>",
},
}
}
----
Could anyone experienced kindly present a way how to get such table from the attached Excel XML file?
TIA.
Best regards,
Lukas
--
Ing. Lukáš Procházka [mailto:LPr@pontex.cz]
Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz]
Bezová 1658
147 14 Praha 4
Tel: +420 244 062 238
Fax: +420 244 461 038
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Test.xml --]
[-- Type: text/xml; name="Test.xml", Size: 8333 bytes --]
<?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>Ing. Lukáš Procházka</Author>
<LastAuthor>LPr</LastAuthor>
<LastPrinted>2008-05-05T16:32:23Z</LastPrinted>
<Created>1999-03-17T11:22:56Z</Created>
<LastSaved>2010-02-14T15:45:18Z</LastSaved>
<Company>Pontex s.r.o.</Company>
<Version>11.9999</Version>
</DocumentProperties>
<OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<AllowPNG/>
</OfficeDocumentSettings>
<ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<SupBook>
<AltStartup>LP.xls</AltStartup>
<SheetName>.</SheetName>
<Xct>
<Count>0</Count>
<SheetIndex>0</SheetIndex>
</Xct>
</SupBook>
<WindowHeight>10875</WindowHeight>
<WindowWidth>15480</WindowWidth>
<WindowTopX>120</WindowTopX>
<WindowTopY>30</WindowTopY>
<AcceptLabelsInFormulas/>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
<Styles>
<Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Center"/>
<Borders/>
<Font ss:FontName="Tahoma" x:CharSet="238" x:Family="Swiss"/>
<Interior/>
<NumberFormat/>
<Protection/>
</Style>
<Style ss:ID="s21">
<Font ss:FontName="Tahoma" x:CharSet="238" x:Family="Swiss" ss:Italic="1"/>
</Style>
<Style ss:ID="s22">
<Font ss:FontName="Tahoma" x:CharSet="238" x:Family="Swiss"/>
</Style>
<Style ss:ID="s23">
<Font ss:FontName="Tahoma" x:CharSet="238" x:Family="Swiss" ss:Italic="1"/>
<Interior ss:Color="#CCFFCC" ss:Pattern="Solid"/>
</Style>
<Style ss:ID="s24">
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
<Font ss:FontName="Tahoma" x:CharSet="238" x:Family="Swiss" ss:Italic="1"/>
</Style>
<Style ss:ID="s25">
<Borders>
<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>
</Borders>
</Style>
<Style ss:ID="s26">
<Borders/>
<Font ss:FontName="Tahoma" x:CharSet="238" x:Family="Swiss" ss:Italic="1"/>
</Style>
<Style ss:ID="s27">
<Borders/>
</Style>
</Styles>
<Worksheet ss:Name="1">
<Table ss:ExpandedColumnCount="256" ss:ExpandedRowCount="4" x:FullColumns="1"
x:FullRows="1">
<Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="45.75"/>
<Column ss:StyleID="s22" ss:AutoFitWidth="0" ss:Width="45.75"/>
<Column ss:AutoFitWidth="0" ss:Width="45.75" ss:Span="253"/>
<Row ss:StyleID="s21">
<Cell><Data ss:Type="String">#something</Data></Cell>
<Cell ss:StyleID="s22"/>
</Row>
<Row ss:Index="3">
<Cell ss:Index="2"><Data ss:Type="String">AAA</Data></Cell>
<Cell><Data ss:Type="Number">1.4</Data><Comment ss:Author="LPr"
ss:ShowAlways="1"><ss:Data xmlns="http://www.w3.org/TR/REC-html40"><Font
html:Size="8" html:Color="#000000">alpha.cc</Font></ss:Data></Comment></Cell>
</Row>
<Row>
<Cell ss:Index="2"><Data ss:Type="String">BBB</Data></Cell>
<Cell><Data ss:Type="Number">1.5</Data><Comment ss:Author="LPr"
ss:ShowAlways="1"><ss:Data xmlns="http://www.w3.org/TR/REC-html40"><Font
html:Size="8" html:Color="#000000">al</Font><B><Font html:Size="8"
html:Color="#000000">pha</Font></B><Font html:Size="8" html:Color="#000000">.cc</Font></ss:Data></Comment></Cell>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Layout x:CenterHorizontal="1"/>
<Header x:Margin="0.59055118110236227"/>
<Footer x:Margin="0.51181102362204722"
x:Data="&R&"Tahoma,Kurzíva"&8&Z&F [&A], &P/&N, &D"/>
<PageMargins x:Bottom="0.70866141732283472" x:Left="0.51181102362204722"
x:Right="0.51181102362204722" x:Top="0.59055118110236227"/>
</PageSetup>
<Print>
<ValidPrinterInfo/>
<PaperSizeIndex>9</PaperSizeIndex>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<Selected/>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Imp">
<Table ss:ExpandedColumnCount="256" ss:ExpandedRowCount="11" x:FullColumns="1"
x:FullRows="1">
<Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="45.75"/>
<Column ss:AutoFitWidth="0" ss:Width="45.75" ss:Span="254"/>
<Row ss:StyleID="s21">
<Cell ss:Index="11" ss:StyleID="s23"/>
</Row>
<Row ss:Index="10" ss:StyleID="s25">
<Cell ss:StyleID="s24"/>
</Row>
<Row ss:StyleID="s27">
<Cell ss:StyleID="s26"/>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Layout x:CenterHorizontal="1"/>
<Header x:Margin="0.59055118110236227"/>
<Footer x:Margin="0.51181102362204722"
x:Data="&R&"Tahoma,Kurzíva"&8&Z&F [&A], &P/&N, &D"/>
<PageMargins x:Bottom="0.70866141732283472" x:Left="0.51181102362204722"
x:Right="0.51181102362204722" x:Top="0.59055118110236227"/>
</PageSetup>
<Print>
<ValidPrinterInfo/>
<PaperSizeIndex>9</PaperSizeIndex>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="Exp">
<Table ss:ExpandedColumnCount="256" ss:ExpandedRowCount="40" x:FullColumns="1"
x:FullRows="1">
<Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="45.75"/>
<Column ss:AutoFitWidth="0" ss:Width="45.75" ss:Span="254"/>
<Row ss:StyleID="s21">
<Cell ss:Index="11" ss:StyleID="s23"/>
</Row>
<Row ss:Index="10" ss:StyleID="s25">
<Cell ss:StyleID="s24"/>
</Row>
<Row ss:Index="40" ss:StyleID="s25">
<Cell ss:StyleID="s24"/>
</Row>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Layout x:CenterHorizontal="1"/>
<Header x:Margin="0.59055118110236227"/>
<Footer x:Margin="0.51181102362204722"
x:Data="&R&"Tahoma,Kurzíva"&8&Z&F [&A], &P/&N, &D"/>
<PageMargins x:Bottom="0.70866141732283472" x:Left="0.51181102362204722"
x:Right="0.51181102362204722" x:Top="0.59055118110236227"/>
</PageSetup>
<Print>
<ValidPrinterInfo/>
<PaperSizeIndex>9</PaperSizeIndex>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
<Worksheet ss:Name="<Template>">
<Table ss:ExpandedColumnCount="256" ss:ExpandedRowCount="1" x:FullColumns="1"
x:FullRows="1">
<Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="45.75"/>
<Column ss:AutoFitWidth="0" ss:Width="45.75" ss:Span="254"/>
<Row ss:StyleID="s21"/>
</Table>
<WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
<PageSetup>
<Layout x:CenterHorizontal="1"/>
<Header x:Margin="0.59055118110236227"/>
<Footer x:Margin="0.51181102362204722"
x:Data="&R&"Tahoma,Kurzíva"&8&Z&F [&A], &P/&N, &D"/>
<PageMargins x:Bottom="0.70866141732283472" x:Left="0.51181102362204722"
x:Right="0.51181102362204722" x:Top="0.59055118110236227"/>
</PageSetup>
<Print>
<ValidPrinterInfo/>
<PaperSizeIndex>9</PaperSizeIndex>
<HorizontalResolution>600</HorizontalResolution>
<VerticalResolution>600</VerticalResolution>
</Print>
<ProtectObjects>False</ProtectObjects>
<ProtectScenarios>False</ProtectScenarios>
</WorksheetOptions>
</Worksheet>
</Workbook>
[-- Attachment #3: Type: text/plain, Size: 485 bytes --]
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage : http://www.pragma-ade.nl / http://tex.aanhet.net
archive : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
next reply other threads:[~2012-11-14 15:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-14 15:45 Procházka Lukáš Ing. - Pontex s. r. o. [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-11-14 15:44 Procházka Lukáš Ing. - Pontex s. r. o.
2012-11-14 15:50 ` luigi scarso
2012-11-14 15:52 ` Procházka Lukáš Ing. - Pontex s. r. o.
2012-11-14 16:22 ` luigi scarso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=op.wnrsp1w1tpjj8f@lpr \
--to=lpr@pontex.cz \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).