Giter Club home page Giter Club logo

slaxml's Introduction

SLAXML

SLAXML is a pure-Lua SAX-like streaming XML parser. It is more robust than many (simpler) pattern-based parsers that exist (such as mine), properly supporting code like <expr test="5 > 7" />, CDATA nodes, comments, namespaces, and processing instructions.

It is currently not a truly valid XML parser, however, as it allows certain XML that is syntactically-invalid (not well-formed) to be parsed without reporting an error.

Features

  • Pure Lua in a single file (two files if you use the DOM parser).
  • Streaming parser does a single pass through the input and reports what it sees along the way.
  • Supports processing instructions (<?foo bar?>).
  • Supports comments (<!-- hello world -->).
  • Supports CDATA sections (<![CDATA[ whoa <xml> & other content as text ]]>).
  • Supports namespaces, resolving prefixes to the proper namespace URI (<foo xmlns="bar"> and <wrap xmlns:bar="bar"><bar:kittens/></wrap>).
  • Supports unescaped greater-than symbols in attribute content (a common failing for simpler pattern-based parsers).
  • Unescapes named XML entities (&lt; &gt; &amp; &quot; &apos;) and numeric entities (e.g. &#10;) in attributes and text nodes (but—properly—not in comments or CDATA). Properly handles edge cases like &#38;amp;.
  • Optionally ignore whitespace-only text nodes (as appear when indenting XML markup).
  • Includes an optional DOM parser that is both a convenient way to pull in XML to use as well as a nice example of using the streaming parser.
    • DOM module also provides DOM-to-XML serialization, including options for pretty-printing and sorting (making plain-text diffs sane). Parse XML, modify Lua tables, and then round-trip the results back to XML.
  • Does not add any keys to the global namespace.

Usage

local SLAXML = require 'slaxml'

local myxml = io.open('my.xml'):read('*all')

-- Specify as many/few of these as you like
parser = SLAXML:parser{
  startElement = function(name,nsURI,nsPrefix)       end, -- When "<foo" or <x:foo is seen
  attribute    = function(name,value,nsURI,nsPrefix) end, -- attribute found on current element
  closeElement = function(name,nsURI)                end, -- When "</foo>" or </x:foo> or "/>" is seen
  text         = function(text,cdata)                end, -- text and CDATA nodes (cdata is true for cdata nodes)
  comment      = function(content)                   end, -- comments
  pi           = function(target,content)            end, -- processing instructions e.g. "<?yes mon?>"
}

-- Ignore whitespace-only text nodes and strip leading/trailing whitespace from text
-- (does not strip leading/trailing whitespace from CDATA)
parser:parse(myxml,{stripWhitespace=true})

If you just want to see if it will parse your document correctly, you can simply do:

local SLAXML = require 'slaxml'
SLAXML:parse(myxml)

…which will cause SLAXML to use its built-in callbacks that print the results as they are seen.

DOM Builder

If you simply want to build tables from your XML, you can alternatively:

local SLAXML = require 'slaxdom' -- also requires slaxml.lua; be sure to copy both files
local doc = SLAXML:dom(myxml)

The returned table is a 'document' composed of tables for elements, attributes, text nodes, comments, and processing instructions. See the following documentation for what each supports.

DOM Table Features

  • Document - the root table returned from the SLAXML:dom() method.
    • doc.type : the string "document"
    • doc.name : the string "#doc"
    • doc.kids : an array table of child processing instructions, the root element, and comment nodes.
    • doc.root : the root element for the document
  • Element
    • someEl.type : the string "element"
    • someEl.name : the string name of the element (without any namespace prefix)
    • someEl.nsURI : the namespace URI for this element; nil if no namespace is applied
    • someAttr.nsPrefix : the namespace prefix string; nil if no prefix is applied
    • someEl.attr : a table of attributes, indexed by name and index
      • local value = someEl.attr['attribute-name'] : any namespace prefix of the attribute is not part of the name
      • local someAttr = someEl.attr[1] : a single attribute table (see below); useful for iterating all attributes of an element, or for disambiguating attributes with the same name in different namespaces
    • someEl.kids : an array table of child elements, text nodes, comment nodes, and processing instructions
    • someEl.el : an array table of child elements only
    • someEl.parent : reference to the parent element or document table
  • Attribute
    • someAttr.type : the string "attribute"
    • someAttr.name : the name of the attribute (without any namespace prefix)
    • someAttr.value : the string value of the attribute (with XML and numeric entities unescaped)
    • someAttr.nsURI : the namespace URI for the attribute; nil if no namespace is applied
    • someAttr.nsPrefix : the namespace prefix string; nil if no prefix is applied
    • someAttr.parent : reference to the owning element table
  • Text - for both CDATA and normal text nodes
    • someText.type : the string "text"
    • someText.name : the string "#text"
    • someText.cdata : true if the text was from a CDATA block
    • someText.value : the string content of the text node (with XML and numeric entities unescaped for non-CDATA elements)
    • someText.parent : reference to the parent element table
  • Comment
    • someComment.type : the string "comment"
    • someComment.name : the string "#comment"
    • someComment.value : the string content of the attribute
    • someComment.parent : reference to the parent element or document table
  • Processing Instruction
    • somePI.type : the string "pi"
    • somePI.name : the string name of the PI, e.g. <?foo …?> has a name of "foo"
    • somePI.value : the string content of the PI, i.e. everything but the name
    • somePI.parent : reference to the parent element or document table

Finding Text for a DOM Element

The following function can be used to calculate the "inner text" for an element:

function elementText(el)
  local pieces = {}
  for _,n in ipairs(el.kids) do
    if n.type=='element' then pieces[#pieces+1] = elementText(n)
    elseif n.type=='text' then pieces[#pieces+1] = n.value
    end
  end
  return table.concat(pieces)
end

local xml  = [[<p>Hello <em>you crazy <b>World</b></em>!</p>]]
local para = SLAXML:dom(xml).root
print(elementText(para)) --> "Hello you crazy World!"

A Simpler DOM

If you want the DOM tables to be easier to inspect you can supply the simple option via:

local dom = SLAXML:dom(myXML,{ simple=true })

In this case the document will have no root property, no table will have a parent property, elements will not have the el collection, and the attr collection will be a simple array (without values accessible directly via attribute name). In short, the output will be a strict hierarchy with no internal references to other tables, and all data represented in exactly one spot.

Serializing the DOM

You can serialize any DOM table to an XML string by passing it to the SLAXML:xml() method:

local SLAXML = require 'slaxdom'
local doc = SLAXML:dom(myxml)
-- ...modify the document...
local xml = SLAXML:xml(doc)

The xml() method takes an optional table of options as its second argument:

local xml = SLAXML:xml(doc,{
  indent = 2,    -- each pi/comment/element/text node on its own line, indented by this many spaces
  indent = '\t', -- ...or, supply a custom string to use for indentation
  sort   = true, -- sort attributes by name, with no-namespace attributes coming first
  omit   = {...} -- an array of namespace URIs; removes elements and attributes in these namespaces
})

When using the indent option, you likely want to ensure that you parsed your DOM using the stripWhitespace option. This will prevent you from having whitespace text nodes between elements that are then placed on their own indented line.

Some examples showing the serialization options:

local xml = [[
<!-- a simple document showing sorting and namespace culling -->
<r c="1" z="3" b="2" xmlns="uri1" xmlns:x="uri2" xmlns:a="uri3">
  <e a:foo="f" x:alpha="a" a:bar="b" alpha="y" beta="beta" />
  <a:wrap><f/></a:wrap>
</r>
]]

local dom = SLAXML:dom(xml, {stripWhitespace=true})

print(SLAXML:xml(dom))
--> <!-- a simple document showing sorting and namespace culling --><r c="1" z="3" b="2" xmlns="uri1" xmlns:x="uri2" xmlns:a="uri3"><e a:foo="f" x:alpha="a" a:bar="b" alpha="y" beta="beta"/><a:wrap><f/></a:wrap></r>

print(SLAXML:xml(dom, {indent=2}))
--> <!-- a simple document showing sorting and namespace culling -->
--> <r c="1" z="3" b="2" xmlns="uri1" xmlns:x="uri2" xmlns:a="uri3">
-->   <e a:foo="f" x:alpha="a" a:bar="b" alpha="y" beta="beta"/>
-->   <a:wrap>
-->     <f/>
-->   </a:wrap>
--> </r>

print(SLAXML:xml(dom.root.kids[2]))
--> <a:wrap><f/></a:wrap>
-- NOTE: you can serialize any DOM table node, not just documents

print(SLAXML:xml(dom.root.kids[1], {indent=2, sort=true}))
--> <e alpha="y" beta="beta" a:bar="b" a:foo="f" x:alpha="a"/>
-- NOTE: attributes with no namespace come first

print(SLAXML:xml(dom, {indent=2, omit={'uri3'}}))
--> <!-- a simple document showing sorting and namespace culling -->
--> <r c="1" z="3" b="2" xmlns="uri1" xmlns:x="uri2">
-->   <e x:alpha="a" alpha="y" beta="beta"/>
--> </r>
-- NOTE: Omitting a namespace omits:
--       * namespace declaration(s) for that space
--       * attributes prefixed for that namespace
--       * elements in that namespace, INCLUDING DESCENDANTS

print(SLAXML:xml(dom, {indent=2, omit={'uri3', 'uri2'}}))
--> <!-- a simple document showing sorting and namespace culling -->
--> <r c="1" z="3" b="2" xmlns="uri1">
-->   <e alpha="y" beta="beta"/>
--> </r>

print(SLAXML:xml(dom, {indent=2, omit={'uri1'}}))
--> <!-- a simple document showing sorting and namespace culling -->
-- NOTE: Omitting namespace for the root element removes everything

Serialization of elements and attributes ignores the nsURI property in favor of the nsPrefix attribute. As such, you can construct DOM's that serialize to invalid XML:

local el = {
  type="element",
  nsPrefix="oops", name="root",
  attr={
    {type="attribute", name="xmlns:nope", value="myuri"},
    {type="attribute", nsPrefix="x", name="wow", value="myuri"}
  }
}
print( SLAXML:xml(el) )
--> <oops:root xmlns:nope="myuri" x:wow="myuri"/>

So, if you want to use a foo prefix on an element or attribute, be sure to add an appropriate xmlns:foo attribute defining that namespace on an ancestor element.

Known Limitations / TODO

  • Does not require or enforce well-formed XML. Certain syntax errors are silently ignored and consumed. For example:
    • foo="yes & no" is seen as a valid attribute
    • <foo></bar> invokes startElement("foo") followed by closeElement("bar")
    • <foo> 5 < 6 </foo> is seen as valid text contents
  • No support for custom entity expansion other than the standard XML entities (&lt; &gt; &quot; &apos; &amp;) and numeric entities (e.g. &#10; or &#x3c;)
  • XML Declarations (<?xml version="1.x"?>) are incorrectly reported as Processing Instructions
  • No support for DTDs
  • No support for extended (Unicode) characters in element/attribute names
  • No support for charset
  • No support for XInclude
  • Does not ensure that the reserved xml prefix is never redefined to an illegal namespace
  • Does not ensure that the reserved xmlns prefix is never used as an element prefix

History

v0.8.1 2022-Dec-31

  • Updating rockspec to prepare for LuaRocks

v0.8 2018-Oct-23

  • Adds SLAXML:xml() to serialize the DOM back to XML.
  • Adds nsPrefix properties to the DOM tables for elements and attributes (needed for round-trip serialization)
  • Fixes test suite to work on Lua 5.2, 5.3.
  • Fixes Issue #10, allowing DOM parser to handle comments/PIs after the root element.
  • Fixes Issue #11, causing DOM parser to preserve whitespace text nodes on the document.
  • Backwards-incompatible change: Removes doc.root key from DOM when simple=true is specified.

v0.7 2014-Sep-26

  • Decodes entities above 127 as UTF8 (decimal and hexadecimal).
    • The encoding specified by the document is (still) ignored. If you parse an XML file encoded in some other format, that intermixes 'raw' high-byte characters with high-byte entities, the result will be a broken encoding.

v0.6.1 2014-Sep-25

  • Fixes Issue #6, adding support for ASCII hexadecimal entities (e.g. &#x3c;). (Thanks Leorex/Ben Bishop)

v0.6 2014-Apr-18

  • Fixes Issue #5 (and more): Namespace prefixes defined on element are now properly applied to the element itself and any attributes using them when the definitions appear later in source than the prefix usage. (Thanks Oliver Kroth.)
  • The streaming parser now supplies the namespace prefix for elements and attributes.

v0.5.3 2014-Feb-12

  • Fixes Issue #3: The reserved xml prefix may be used without pre-declaring it. (Thanks David Durkee.)

v0.5.2 2013-Nov-7

  • Lua 5.2 compatible
  • Parser now errors if it finishes without finding a root element, or if there are unclosed elements at the end. (Proper element pairing is not enforced by the parser, but is—as in previous releases—enforced by the DOM builder.)

v0.5.1 2013-Feb-18

  • <foo xmlns="bar"> now directly generates startElement("foo","bar") with no post callback for namespace required.

v0.5 2013-Feb-18

  • Use the local SLAXML=require 'slaxml' pattern to prevent any pollution of the global namespace.

v0.4.3 2013-Feb-17

  • Bugfix to allow empty attributes, i.e. foo=""
  • closeElement no longer includes namespace prefix in the name, includes the nsURI

v0.4 2013-Feb-16

  • DOM adds .parent references
  • SLAXML.ignoreWhitespace is now :parse(xml,{stripWhitespace=true})
  • "simple" mode for DOM parsing

v0.3 2013-Feb-15

  • Support namespaces for elements and attributes
    • <foo xmlns="barURI"> will call startElement("foo",nil) followed by namespace("barURI") (and then attribute("xmlns","barURI",nil)); you must apply the namespace to your element after creation.
    • Child elements without a namespace prefix that inherit a namespace will receive startElement("child","barURI")
    • <xy:foo> will call startElement("foo","uri-for-xy")
    • <foo xy:bar="yay"> will call attribute("bar","yay","uri-for-xy")
    • Runtime errors are generated for any namespace prefix that cannot be resolved
  • Add (optional) DOM parser that validates hierarchy and supports namespaces

v0.2 2013-Feb-15

  • Supports expanding numeric entities e.g. &#34; -> "
  • Utility functions are local to parsing (not spamming the global namespace)

v0.1 2013-Feb-7

  • Option to ignore whitespace-only text nodes
  • Supports unescaped > in attributes
  • Supports CDATA
  • Supports Comments
  • Supports Processing Instructions

License

Copyright © 2013 Gavin Kistner

Licensed under the MIT License. See LICENSE.txt for more details.

slaxml's People

Contributors

leorex avatar pdesaulniers avatar phrogz avatar quifi avatar vadi2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

slaxml's Issues

test fails

When packaging SLAXML for OpenSUSE, I get this error while running the testsuite:

[    2s] + cd test
[    2s] + lua test.lua
[    2s] ==============================================================================
[    2s] (test suite)
[    2s] ==============================================================================
[    2s] comments: .......pass
[    2s] dom: .........................................................pass
[    2s] dom_entities: ....pass
[    2s] dom_namespaces: ......................pass
[    2s] dom_serializer: pass
[    2s] invalid_documents: .......FAIL!
[    2s] test.lua:225: assertErrors() failed: function: 0x55e0b01f1390 did not raise an error
[    2s] namespace: ....pass
[    2s] serialize_sorting: ....pass
[    2s] serializer: ......pass
[    2s] simplest: .......pass
[    2s] slim_and_trim_dom: .................................pass
[    2s] utf8: ......pass
[    2s] whitespace: ................pass
[    2s] xml_namespace: .pass
[    2s] xml_namespace_immediate_use: ....................pass
[    2s] ------------------------------------------------------------------------------
[    2s] 14/15 tests passed (93.3%)
[    2s] 194 total successful assertions in ~2ms (103579 assertions/second)

DOM parser fails for comment after root

local SLAXML = require 'slaxdom'
SLAXML:dom[[<r/><!-- oops -->]]

--> .\slaxdom.lua:40: attempt to index a nil value (upvalue 'current')
--> stack traceback:
-->         .\slaxdom.lua:40: in field 'comment'
-->         .\slaxml.lua:104: in local 'findComment'
-->         .\slaxml.lua:236: in function 'slaxml.parse'
-->         .\slaxdom.lua:46: in function 'slaxml.dom'
-->         (...tail calls...)
-->         [C]: in ?

Hex XML entity

Hi Gavin, great work with SLAXML.
Regarding XML entity handling, decimal works great but it chokes on hex (in my case I have to deal with &#xD;&#xA;):

For hex entities, eg &#xA;, unescape() is feeding entitySwap with n: # and s: xA

char(xA) causes the error slaxml.lua:57: bad argument #1 to 'char' (number expected, got string)

Prepending the char() input with 0 makes Lua happy with both hex char(0xA) and decimal char(010).

I've only just started with Lua, so I'm not sure the most efficient way, but perhaps it's as simple as char('0'..s)?

slaxml.lua, line 57:

    local entitySwap = function(orig,n,s) return entityMap[s] or n=="#" and char('0'..s) or orig end

Any downside?

Edit: I tested a 40MB OpenStreetMap XML extract. Identical time and memory usage for both unmodified char(s) and modified char('0'..s), so it doesn't appear to affect performance.

unpack error

Lines 168, 170, 174 raise errors when run with Lua 5.2:

lua: .\slaxml.lua:168: attempt to call global 'unpack' (a nil value)

unpack has been moved into the table table in Lua 5.2.

Inserting the following line at line 38 solved the issue, and should make the file compatible with both Lua 5.1 and 5.2:
local unpack = unpack or table.unpack

Serialization uses mix of nsURI and nsPrefix

Building a DOM from scratch to seraialize requires creating nsPrefix properties on elements and attributes, but also maintaining proper nsURI if you want to use the omit option during serialization.

Might be better to remove nsPrefix from the DOM and instead decide the prefix based on the defined prefixes (favoring the closest ancestor), based on parsing xmlns:foo attributes during serialization.

Positive: fewer moving parts to keep track of, and fixes the bug that allows serialization of invalid documents. When serializing subtrees could even provide the option of generating namespace attributes as necessary.

Negative: would probably no longer round-trip something like this:

<a:foo xmlns="uriA" xmlns:a="uriA"><a:bar /></a:foo>

...because the serializer would see that bar was in uriA namespace and deduce that since its parent element had declared that as a default namespace the output out to be:

<foo xmlns="uriA" xmlns:a="uriA"><bar /></foo>

Whitespace text ignored at DOM root

local SLAXML = require 'slaxdom'
SLAXML:dom("<!--a-->\n<r/>", {simple=true})
--> {
-->   type="document",
-->   name="#doc",
-->   kids={
-->     {type="comment", name="#comment", value="a"},
-->     {type="element", name="r", attr={}, kids={}}
-->   }
--> }

Without stripWhitespace=true, we would expect to see a text node between the comment and the root, i.e.

--> {
-->   type="document",
-->   name="#doc",
-->   kids={
-->     {type="comment", name="#comment", value="a"},
-->     {type="text", name="#text", value="\n"},
-->     {type="element", name="r", attr={}, kids={}}
-->   }
--> }

Error with undeclared use of xml: namespace

I was trying out slaxml and used it with this SVG code from Adobe Illustrator:

<!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In  -->
<svg version="1.1"
     xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:a="http://ns.adobe.com/AdobeSVGViewerExtensions/3.0/"
     x="0px" y="0px" width="110.6px" height="82px" viewBox="0 0 110.6 82" enable-background="new 0 0 110.6 82" xml:space="preserve"
    >
<defs>
</defs>
<path fill="#B3B0A1" stroke="#000000" stroke-miterlimit="10" d="M3.8,18.4c0,0-9-14.1,12.8-17.3s28.2,6.4,17.9,20.5
    s-37.8,19.2-0.6,25s105.8-58.3,62.2-11.5S29.4,84.5,12.1,80C-5.2,75.5,2,37,2,37"/>
<path fill="#9B9A91" stroke="#000000" stroke-miterlimit="10" d="M27.5,53c0,0-16-14.8,0-24.4s16-1.9,19.2,5.1
    c3.2,7.1,6.4,12.8,0,16c-6.4,3.2-11.3,6.4-11.3,6.4"/>
</svg>

This gave an error in nsForPrefix because the xmlnamespace was not declared. According to Namespaces in XML, "The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared…." See http://www.w3.org/TR/xml-names/. To work around this I changed the line initializing nsStack to:

local nsStack = {{xml="http://www.w3.org/XML/1998/namespace"}}

I also had to change the check at the end from

if #nsStack > 0 then error(...

to

if #nsStack > 1 then error(...

because of this. It seems like another possible solution would be to put in a hard-coded check in nsForPrefix for xml. Maybe that would be better.

Installation via rockspec does not work

Hello,

I was trying to install the package via luarocks install slaxml-0.7-0.rockspec and it didn't suceed.

After some modifications I managed to do it by:

  • changing the name to slaxml-0.8-0.rockspec, i.e., the name should be exactly <package_name>-<version>.rockspec
  • changing the url in the .rockspec file from "https://github.com/Phrogz/SLAXML.git" to "url = "git://github.com/Phrogz/SLAXML.git"", i.e., replacing https with git

Missing DOCTYPE support

Hi there!
I've faced an issue that slaxdom failed to build a DOM for document that have a <!DOCTYPE>.
w3 says it is valid: https://www.w3.org/TR/xml/#NT-doctypedecl

Minimal test-case:

sd=require"slaxdom"
z=sd:dom("<!DOCTYPE><a></a>")

The error would be:

/usr/share/lua/5.1/slaxdom.lua:34: Document has non-whitespace text at root: '<!DOCTYPE>'
Stack traceback:
  At =[C]:-1 (in global error)
  At @/usr/share/lua/5.1/slaxdom.lua:34 (in field text)
    0031:               end,
    0032:               text = function(value,cdata)
    0033:                       -- documents may only have text node children that are whitespace: https://www.w3.org/TR/xml/#NT-Misc
    0034:                       if current.type=='document' and not value:find('^%s+$') then error(("Document has non-whitespace text at root: '%s'"):format(value:gsub('[\r\n\t]',{['\r']='\\r', ['\n']='\\n', ['\t']='\\t'}))) end
    0035:                       push(current.kids,{type='text',name='#text',cdata=cdata and true or nil,value=value,parent=rich and current or nil})
    0036:               end,
    0037:               comment = function(value)
  At @/usr/share/lua/5.1/slaxml.lua:87 (in upvalue finishText)
    0084:                               text = gsub(text,'%s+$','')
    0085:                               if #text==0 then text=nil end
    0086:                       end
    0087:                       if text then self._call.text(unescape(text),false) end
    0088:               end
    0089:       end
    0090:
  At @/usr/share/lua/5.1/slaxml.lua:125 (in local startElement)
    0122:               if first then
    0123:                       currentElement[2] = nil -- reset the nsURI, since this table is re-used
    0124:                       currentElement[3] = nil -- reset the nsPrefix, since this table is re-used
    0125:                       finishText()
    0126:                       pos = last+1
    0127:                       first,last,match2 = find(xml, '^:([%a_][%w_.-]*)', pos )
    0128:                       if first then
  At @/usr/share/lua/5.1/slaxml.lua:239 (in method parse)
    0236:       while pos<#xml do
    0237:               if state=="text" then
    0238:                       if not (findPI() or findComment() or findCDATA() or findElementClose()) then
    0239:                               if startElement() then
    0240:                                       state = "attributes"
    0241:                               else
    0242:                                       first, last = find( xml, '^[^<]+', pos )
  At @/usr/share/lua/5.1/slaxdom.lua:44 (in method dom)
    0041:                       push(current.kids,{type='pi',name=name,value=value,parent=rich and current or nil})
    0042:               end
    0043:       }
    0044:       builder:parse(xml,opts)
    0045:       return doc
    0046: end
    0047:
  At stdin#22:1 (in  ?)
    0001: z=sd:dom("<!DOCTYPE><a></a>")

For now, I working that around by converting doctype to comment, and "uncommenting" it again right before serialization, but it would be nice if it will work out-of-the box :)

<x:el xmlns:x="foo" /> not supported

Declaring a namespace on the element and also using it on that same element does not work.

./slaxml.lua:90: Cannot find namespace for prefix x
stack traceback:
    [C]: in function 'error'
    ./slaxml.lua:90: in function 'nsForPrefix'
    ./slaxml.lua:103: in function 'startElement'
    ./slaxml.lua:205: in function 'parse'
    ./slaxdom.lua:46: in function 'dom'
    stdin:1: in main chunk
    [C]: ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.