Add support for XmlDecl handlers

Wed, 02 Apr 2014 20:56:58 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 02 Apr 2014 20:56:58 +0100
changeset 18
90da47758f85
parent 17
7f0e6f8bb8e0
child 19
10c30b63873a

Add support for XmlDecl handlers

src/lxplib.c file | annotate | diff | comparison | revisions
src/lxplib.h file | annotate | diff | comparison | revisions
--- a/src/lxplib.c	Wed Apr 02 20:53:54 2014 +0100
+++ b/src/lxplib.c	Wed Apr 02 20:56:58 2014 +0100
@@ -326,6 +326,16 @@
   docall(xpu, 4, 0);
 }
 
+static void f_XmlDecl (void *ud, const XML_Char *version,
+                                 const XML_Char *encoding,
+                                 int standalone) {
+  lxp_userdata *xpu = (lxp_userdata *)ud;
+  if (getHandle(xpu, XmlDeclKey) == 0) return;  /* no handle */
+  lua_pushstring(xpu->L, version);
+  lua_pushstring(xpu->L, encoding);
+  lua_pushboolean(xpu->L, standalone);
+  docall(xpu, 3, 0);
+}
 /* }====================================================== */
 
 
@@ -346,7 +356,7 @@
     "Default", "DefaultExpand", "StartElement", "EndElement",
     "ExternalEntityRef", "StartNamespaceDecl", "EndNamespaceDecl",
     "NotationDecl", "NotStandalone", "ProcessingInstruction",
-    "UnparsedEntityDecl", "StartDoctypeDecl", NULL};
+    "UnparsedEntityDecl", "StartDoctypeDecl", "XmlDecl", NULL};
   if (hasfield(L, "_nonstrict")) return;
   lua_pushnil(L);
   while (lua_next(L, 1)) {
@@ -401,6 +411,8 @@
     XML_SetUnparsedEntityDeclHandler(p, f_UnparsedEntityDecl);
   if (hasfield(L, StartDoctypeDeclKey))
     XML_SetStartDoctypeDeclHandler(p, f_StartDoctypeDecl);
+  if (hasfield(L, XmlDeclKey))
+    XML_SetXmlDeclHandler(p, f_XmlDecl);
   return 1;
 }
 
--- a/src/lxplib.h	Wed Apr 02 20:53:54 2014 +0100
+++ b/src/lxplib.h	Wed Apr 02 20:56:58 2014 +0100
@@ -20,5 +20,6 @@
 #define ProcessingInstructionKey	"ProcessingInstruction"
 #define UnparsedEntityDeclKey		"UnparsedEntityDecl"
 #define StartDoctypeDeclKey		"StartDoctypeDecl"
+#define XmlDeclKey			"XmlDecl"
 
 int luaopen_lxp (lua_State *L);

mercurial