github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

asb / lua-xmlreader

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 2
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (1)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (1)
    • 0.1
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

A Lua implementation of the XmlReader API using libxml2 — Read more

  cancel

http://asbradbury.org/projects/lua-xmlreader/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

remove inline documentation 
asb (author)
Sun Aug 03 04:56:26 -0700 2008
commit  1557d9034f2033d06fe1e34aa89ac75493477fe4
tree    9895beaf378ce1503acfe1dd53f4d5c73e8935da
parent  e8e0bd2117b5b135121fa40bfec9b99dc4dd8734
lua-xmlreader /
name age
history
message
file DOCUMENTATION.mkd Loading commit data...
file LICENSE
file Makefile Sat Aug 02 10:36:22 -0700 2008 Remove redundant doc target from Makefile, add ... [asb]
file README.mkd Sat Aug 02 08:02:25 -0700 2008 add README.mkd [asb]
file TODO Sun Aug 03 04:24:28 -0700 2008 first version of rewritten and separated docume... [asb]
file error.c
file error.h Sat Aug 02 07:47:29 -0700 2008 check in 0.1 sources [asb]
file example.lua
file lua-xmlreader-dev-1.rockspec Sat Aug 02 07:59:37 -0700 2008 add rockspec [asb]
file xmlreader.c
README.mkd

lua-xmlreader

Provides the XmlReader API to Lua applications using LibXML2. XmlReader is an API introduced in C# that is arguably easier to use than SAX. It provides a pull interface where you control the reader, which is a cursor moving along the document. Call methods such as reader:name() to get information about the current node and reader:read() to advance to the next. This has the advantage versus a tree model such as DOM that the whole document does not need to be loaded into memory at once. The many articles and tutorials available online referring to XmlReader/XmlTextReader in C#, Java or other languages should all be useful if you want to better understand this method of handling XML. lua-xmlreader depends on the libxml2 library.

Project links

  • Download
  • Documentation
  • Source

Release history

  • lua-xmlreader-0.1 (2008-01-25)
    • first public release

Related links

  • LibXML2
  • DotGNU XmlReader

Example

Below is a fairly simple example demonstrating how you extract information from an XML document using an XmlReader. It prints each element along with its attributes.

#! /usr/bin/env lua
require('xmlreader')

local example_xml = [[
<?xml version="1.0" encoding="utf-8"?>
<library>
  <book id='1'>
    <title>Green Eggs and Ham</title>
    <author>Dr. Seuss</author>
  </book>
  <book id='2'>
    <title>Where the Wild Things Are</title>
    <author>Maurice Sendak</author>
  </book>
</library>
]]

local r = assert(xmlreader.from_string(example_xml))

while (r:read()) do
  local leadingws = ('    '):rep(r:depth())
  if (r:node_type() == 'element') then
    io.write(('%s%s:'):format(leadingws, r:name()))
    while (r:move_to_next_attribute()) do
      io.write((' %s=%q'):format(r:name(), r:value()))
    end
    io.write('\n')
  end
end

When executed, this would output:

library:
    book: id="1"
        title:
        author:
    book: id="2"
        title:
        author:

License

lua-xmlreader is distributed under the MIT license.

Copyright (c) 2008 A.S. Bradbury

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

Contact

Author: A.S. Bradbury
Email: asb@asbradbury.org
Homepage: http://asbradbury.org/

Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server