3
#include <libxml/xmlmemory.h>
4
#include <libxml/debugXML.h>
5
#include <libxml/HTMLtree.h>
6
#include <libxml/xmlIO.h>
7
#include <libxml/DOCBparser.h>
8
#include <libxml/xinclude.h>
9
#include <libxml/catalog.h>
10
#include <libxml/xmlversion.h>
11
#include <libxslt/xslt.h>
12
#include <libxslt/xsltInternals.h>
13
#include <libxslt/transform.h>
14
#include <libxslt/xsltutils.h>
15
#include <libxslt/xsltconfig.h>
18
#include "interpret.h"
20
#include "pike_macros.h"
21
#include "module_support.h"
28
#define safe_push_text(_txt_) if ((_txt_)) push_text((_txt_)); else push_int(0)
30
static void init_dom(struct object * o);
31
static void exit_dom(struct object * o);
33
static void init_node(struct object * o);
34
static void exit_node(struct object * o);
38
void f_create_dom(INT32 args)
42
struct pike_string *rootStr = NULL;
45
Pike_error("Wrong number of arguments for creation !");
46
else if ( ARG(1).type != T_STRING )
47
Pike_error("Incorrect type for argument 1: expected a string !");
48
rootStr = ARG(1).u.string;
50
doc = xmlNewDoc("1.0");
51
THISDOM->domDoc = doc;
55
Pike_error("Unable to create new XML document.\n");
57
node = xmlNewNode(NULL, (xmlChar *)rootStr->str);
58
xmlDocSetRootElement(doc, node);
59
THISDOM->rootNode = node;
63
Pike_error("Unable to find Root Node.\n");
68
void f_get_root(INT32 args)
71
xmlNodePtr node = THISDOM->rootNode;
72
push_text(node->name);
74
OBJ2_NODE(o)->node = node;
78
void f_create_node(INT32 args)
80
struct mapping *attributes = NULL;
81
struct pike_string *name = NULL;
87
if ( ARG(2).type != T_MAPPING )
88
Pike_error("second argument is attribute mapping of node !");
89
attributes = ARG(2).u.mapping;
93
Pike_error("invalid number of arguments to create node !");
95
if ( ARG(1).type != T_STRING )
96
Pike_error("first argument needs to be name of the node !");
97
name = ARG(1).u.string;
100
node = xmlNewNode(NULL, (xmlChar *)name->str);
101
THISNODE->node = node;
103
if ( attributes != NULL ) {
104
struct svalue sind, sval;
107
MY_MAPPING_LOOP(attributes, count, k)
111
if(!(sind.type == T_STRING && sval.type == T_STRING)) {
114
xmlNewProp(node, sind.u.string->str, sval.u.string->str);
122
void f_add_prop(INT32 args)
124
xmlNodePtr node, current;
127
Pike_error("add_prop: invalid number of arguments : expected key/value");
128
if ( ARG(1).type != T_STRING || ARG(2).type != T_STRING )
129
Pike_error("Incorrect type for arguments: expected string, string !");
130
current = THISNODE->node;
132
xmlNewProp(current, ARG(1).u.string->str, ARG(2).u.string->str);
138
void f_add_data(INT32 args)
142
Pike_error("invalid number of arguments to add_data: expected string");
143
if ( ARG(1).type != T_STRING )
144
Pike_error("Incorrect type for argument 1: expected string");
145
node = xmlNewText(ARG(1).u.string->str);
146
xmlAddChild(THISNODE->node, node);
151
void f_add_child(INT32 args)
156
Pike_error("invalid number of arguments for add_child: expected object");
157
if ( ARG(1).type != T_OBJECT )
158
Pike_error("Incorrect type for argument 1: expected an object !");
159
struct object* node = ARG(1).u.object;
160
current = THISNODE->node;
162
xmlAddChild(current, OBJ2_NODE(node)->node);
167
void f_render_xml(INT32 args)
173
buf = xmlBufferCreate();
174
dumped = xmlNodeDump(buf, THISDOM->domDoc, THISDOM->rootNode, 1, 1);
179
str = (char *)xmlStrdup(buf->content);
187
int _init_xml_dom(void)
190
ADD_STORAGE(dom_storage);
192
set_init_callback(init_dom);
193
set_exit_callback(exit_dom);
195
ADD_FUNCTION("create", f_create_dom, tFunc(tString, tVoid), 0);
196
ADD_FUNCTION("render_xml", f_render_xml, tFunc(tVoid, tString), 0);
197
ADD_FUNCTION("get_root", f_get_root, tFunc(tVoid, tObj), 0);
198
dom_program = end_program();
200
add_program_constant("DOM", dom_program, 0);
203
ADD_STORAGE(node_storage);
205
set_init_callback(init_node);
206
set_exit_callback(exit_node);
207
ADD_FUNCTION("create", f_create_node, tFunc(tString tOr(tMapping, tVoid), tVoid), 0);
208
ADD_FUNCTION("add_data", f_add_data, tFunc(tString, tInt), 0);
209
ADD_FUNCTION("add_prop", f_add_prop, tFunc(tString tString, tInt), 0);
210
ADD_FUNCTION("add_child", f_add_child, tFunc(tObj, tInt), 0);
211
node_program = end_program();
212
add_program_constant("Node", node_program, 0);
215
int _shutdown_xml_dom(void)
220
static void init_dom(struct object *o)
225
THISDOM->domDoc = NULL;
226
THISDOM->rootNode = NULL;
229
static void init_node(struct object *o)
234
THISNODE->node = NULL;
237
static void exit_dom(struct object *o)
244
static void exit_node(struct object *o)