summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/luatex/luaxml
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2013-05-27 01:55:10 +0000
committerNorbert Preining <preining@logic.at>2013-05-27 01:55:10 +0000
commit2ddd33f9dce3a1254f97dc5e560f9576ba63f3ef (patch)
tree16db9c0b6f9d9113fda2edd944a5ec5169bb298f /Master/texmf-dist/doc/luatex/luaxml
parent0da954038fc199402b8d190a323de81a997709c4 (diff)
luaxml update 5/27
git-svn-id: svn://tug.org/texlive/trunk@30712 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/luatex/luaxml')
-rw-r--r--Master/texmf-dist/doc/luatex/luaxml/luaxml.pdfbin111453 -> 114519 bytes
-rw-r--r--Master/texmf-dist/doc/luatex/luaxml/luaxml.tex68
2 files changed, 59 insertions, 9 deletions
diff --git a/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf b/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf
index cddfdcdf5d9..3a6967c9c66 100644
--- a/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf
+++ b/Master/texmf-dist/doc/luatex/luaxml/luaxml.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex b/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex
index 34363fbcf04..4dcff6a51a1 100644
--- a/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex
+++ b/Master/texmf-dist/doc/luatex/luaxml/luaxml.tex
@@ -4,6 +4,7 @@
\begin{document}
\title{The \textsc{LuaXML} library}
\author{Paul Chakravarti \and Michal Hoftich}
+ \date{Version 0.0.2\\May 25, 2013}
\maketitle
\tableofcontents
\section*{Introduction}
@@ -87,6 +88,56 @@ Note that |simpleTreeHandler| creates tables that can be easily accessed using s
\end{verbatim}
it produces wrong results. It is useful mostly for data |xml| files, not for text formats like |xhtml|.
+For complex xml documents with mixed content, |domHandler| is capable of representing any valid XML document:
+
+\begin{verbatim}
+-- dom-sample.lua
+-- next line enables scripts called with texlua to use luatex libraries
+kpse.set_program_name("luatex")
+function traverseDom(parser, current,level)
+ local level = level or 0
+ local spaces = string.rep(" ",level)
+ local root= current or parser._handler.root
+ local name = root._name or "unnamed"
+ local xtype = root._type or "untyped"
+ local attributes = root._attr or {}
+ if xtype == "TEXT" then
+ print(spaces .."TEXT : " .. root._text)
+ else
+ print(spaces .. xtype .. " : " .. name)
+ end
+ for k, v in pairs(attributes) do
+ print(spaces .. " ".. k.."="..v)
+ end
+ local children = root._children or {}
+ for _, child in ipairs(children) do
+ traverseDom(parser,child, level + 1)
+ end
+end
+
+local xml = require('luaxml-mod-xml')
+local handler = require('luaxml-mod-handler')
+local x = '<p>hello <a href="http://world.com/">world</a>, how are you?</p>'
+local domHandler = handler.domHandler()
+local parser = xml.xmlParser(domHandler)
+parser:parse(x)
+traverseDom(parser)
+\end{verbatim}
+
+This produces after running with |texlua dom-sample.lua|:
+
+\begin{verbatim}
+ROOT : unnamed
+ ELEMENT : p
+ TEXT : hello
+ ELEMENT : a
+ href=http://world.com/
+ TEXT : world
+ TEXT : , how are you?
+\end{verbatim}
+
+With \verb|domHandler|, you can process documents with mixed content, like \verb|xhtml|.
+
Because at the moment it is intended mainly as support for the odsfile package, there is little documentation,
what follows is the original documentation of |LuaXML|, which may be little bit obsolete now.
@@ -159,8 +210,8 @@ differently.
The following events are generated by the tokeniser
\begin{verbatim}
-handler:start - Start Tag
-handler:end - End Tag
+handler:starttag - Start Tag
+handler:endtag - End Tag
handler:text - Text
handler:decl - XML Declaration
handler:pi - Processing Instruction
@@ -179,8 +230,8 @@ callbacks - ie.
\begin{tabular}{llp{5cm}}
Callback & val & attrs (table)\\
\hline
-start & name & |{ attributes (name=val).. }|\\
-end & name & nil\\
+starttag & name & |{ attributes (name=val).. }|\\
+endtag & name & nil\\
text & |<text>| & nil\\
cdata & |<text> | & nil\\
decl & "xml" & |{ attributes (name=val).. }|\\
@@ -196,11 +247,11 @@ dtd & root element & \begin{verbatim}{ _root = <Root Element>,
}\end{verbatim}\\
\end{tabular}
-(start \& end provide the character positions of the start/end of the
+(starttag \& endtag provide the character positions of the start/end of the
element)
XML data is passed to the parser instance through the `parse' method
-(Nore: must be passed a single string currently)
+(Note: must be passed as single string currently)
\section{Options}
@@ -232,8 +283,8 @@ NOTE: Boolean options must be set to `nil' not `0'
Create a handler instance -
\begin{verbatim}
-h = { start = function(t,a,s,e) .... end,
- end = function(t,a,s,e) .... end,
+h = { starttag = function(t,a,s,e) .... end,
+ endtag = function(t,a,s,e) .... end,
text = function(t,a,s,e) .... end,
cdata = text }
\end{verbatim}
@@ -292,7 +343,6 @@ node = { _name = <Element Name>,
}
\end{verbatim}
-The dom structure is capable of representing any valid XML document
\subsubsection{simpleTreeHandler}
simpleTreeHandler is a simplified handler which attempts to generate a