lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On 16 Dec 2007, at 6:04 , Ken Smith wrote:

On Dec 16, 2007 8:31 AM, peterhickman <peterhi@ntlworld.com> wrote:
After playing around with the BadgerFish implementation mentioned in
a previous post I asked myself "how hard would it be to implement an
XML parser in Lua?" This is the result, here http://
peterhi.dyndns.org/plxml/index.html

I was looking for something like this recently.  In particular, I need
something that can take tabular data and dump it as XML.  Thanks for
doing it for me!  In your to do list, you mention handling > symbols.
If you do this work before I do, don't forget < (&lt;), & (&amp;), "
(&quot;), and ' (&#39;).

The problem is that I am using the naked > (as opposed to the &gt;) to mark the end of a token. The following is valid XML but will choke my parser.

<?xml version="1.0?>
<doc>
  <p class="bro>ken">Hi there</p>
</doc>

The > in the attribute value is perfectly valid XML, if a little unusual, but my parser will parse it as

PI: <?xml version="1.0"?>
ELEMENT: <doc>
ELEMENT: <p class="bro>
TEXT: ken">Hi there
ELEMENT: </p>
ELEMENT: </doc>

Which is completely wrong. It's fixable but at present it is an example of a shortcoming in the design.


My particular need is to fabricate XML out of thin air rather than
read and modify a source document.  How would you recommend I do so in
order to preserve the well-formedness of the Lua table?

Presently my code provides no constructors for new nodes, the likes of makepi() are there to deconstruct the input string into a table. The problem is that I am so used to OO programing that getting my head around how to do things without OO is difficult. I keep thinking "all we need is an add method", but the tables are not objects. Of course I just need to get my head around Lua OO and I will have that sorted.


   Thanks,
   Ken Smith

--
Java: There is only so much you can do in a straight jacket