From ce84a003a426743f7379223da42f868cf5d79efe Mon Sep 17 00:00:00 2001 From: gyani Date: Sun, 14 Jun 2015 06:20:06 +0000 Subject: [PATCH] Added documentation for parseDOM. Fixed a few typos in the original documentation --- nselib/slaxml.lua | 62 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/nselib/slaxml.lua b/nselib/slaxml.lua index 4e134ebf4..d3be644fc 100644 --- a/nselib/slaxml.lua +++ b/nselib/slaxml.lua @@ -9,6 +9,7 @@ -- The streaming parser does a simple pass through the input and reports what it sees along the way. -- You can optionally ignore white-space only text nodes using the stripWhitespace option. -- The library contains the parser class and the parseDOM function. +-- -- Basic Usage of the library: -- -- local parser = parser:new() @@ -32,7 +33,57 @@ -- -- parseDOM(xmlbody, options) -- --- @author "Gavin Kistner, Gyanendra Mishra" +-- +-- DOM Table Features +-- +-- Document - the root table returned from the parseDOM() 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 +-- 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] : an 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.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.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 +-- +-- someComment.type : the string "pi" +-- someComment.name : the string name of the PI, e.g. has a name of "foo" +-- someComment.value : the string content of the PI, i.e. everything but the name +-- someComment.parent : reference to the parent element or document table +-- +-- @author {"Gavin Kistner", "Gyanendra Mishra"} --[=====================================================================[ v0.7 Copyright © 2013-2014 Gavin Kistner ; MIT Licensed @@ -56,7 +107,7 @@ local debugging_level = tonumber(stdnse.get_script_args('slaxml.debug')) or 3 local DEFAULT_CALLBACKS = { --- A call back for processing instructions. -- To use define pi = function(, ) end in parser._call table. - -- Executes whenever a comment is found. + -- Executes whenever a processing instruction is found. -- @param target the PI target -- @param content any value not containing the sequence '?>' pi = function(target,content) @@ -126,6 +177,7 @@ parser = { return o end, --- Parses the xml in sax like manner. + -- @self The parser object. -- @param xml The xml body to be parsed. -- @param options Options if any specified. parseSAX = function(self, xml, options) @@ -333,9 +385,9 @@ parser = { } ---- Parses xml and spits out dom --- @param xml, the xml body to be parsed. --- @param options if any to use. Supporst stripWhitespaces currently. +--- Parses xml and outputs a dom table. +-- @param xml the xml body to be parsed. +-- @param options if any to use. Supports stripWhitespaces currently. function parseDOM (xml, options) if not options then options={} end local rich = not options.simple