Permalink
Browse files

Send "prefix mapping events" to the delegate.

  • Loading branch information...
anagromataf committed Apr 10, 2009
1 parent 8cc7c19 commit 3d3ec871af683d43f2745c242fd3b7f7ed51f28b
Showing with 27 additions and 1 deletion.
  1. +9 −0 KonocoXML.m
  2. +1 −0 konoco_sax.h
  3. +14 −1 konoco_sax_namespace_handler.c
  4. +3 −0 testfile.xml
View
@@ -108,6 +108,14 @@
};
}
+void
+delegate_xmlns(void * parser, void * data, konoco_buffer * prefix, konoco_buffer * namespace)
+{
+ printf("Prefix mapping: '%.*s' '%.*s'\n",
+ prefix->length, prefix->data,
+ namespace->length, namespace->data);
+}
+
void
delegate_error(void * parser, void * data, const char * error)
{
@@ -129,6 +137,7 @@ int main (int argc, const char * argv[]) {
delegate.end_element = &delegate_end_element;
delegate.attribute = &delegate_attribute;
delegate.characters = &delegate_characters;
+ delegate.xmlns = &delegate_xmlns;
delegate.error = &delegate_error;
void * parser = konoco_sax_create(1024, 0);
View
@@ -43,6 +43,7 @@ typedef struct _konoco_sax_delegate {
void (*end_element)(void * parser, void * data, konoco_buffer * name, konoco_buffer * namespace);
void (*attribute)(void * parser, void * data, konoco_buffer * name, konoco_buffer * namespace, konoco_buffer * value);
void (*characters)(void * parser, void * data, konoco_buffer * text);
+ void (*xmlns)(void * parser, void * data, konoco_buffer * prefix, konoco_buffer * namespace);
void (*error)(void * parser, void * data, const char * msg);
// internal fields & functions
@@ -204,20 +204,33 @@ void
ns_delegate_attribute(void * p, void * data, konoco_buffer * name, konoco_buffer * namespace, konoco_buffer * value)
{
parser_handle * parser = (parser_handle *)p;
-
+ ns_delegate_data * ns_data = (ns_delegate_data *)data;
+
qname qname;
if (split_prefix(&qname, name)){
if (konoco_buffer_eq_str(&qname.prefix, "xmlns")) {
assert(parser->ns_resolver);
konoco_namespace_resolver_set(parser->ns_resolver, &qname.name, value);
+ if (ns_data->orig_delegate->xmlns) {
+ (ns_data->orig_delegate->xmlns)(parser,
+ ns_data->orig_delegate->data,
+ &qname.name,
+ value);
+ };
} else {
append_attribute(parser, &qname.prefix, &qname.name, value);
}
} else {
if (konoco_buffer_eq_str(&qname.name, "xmlns")) {
assert(parser->ns_resolver);
konoco_namespace_resolver_set(parser->ns_resolver, &qname.prefix, value);
+ if (ns_data->orig_delegate->xmlns) {
+ (ns_data->orig_delegate->xmlns)(parser,
+ ns_data->orig_delegate->data,
+ &qname.prefix,
+ value);
+ };
} else {
append_attribute(parser, &qname.prefix, &qname.name, value);
};
View
@@ -2,5 +2,8 @@
<foo bar="baz" xmlns="http://example.com">
<bar/><bar xmlns:a="uri:xyz" baz="123" a:b="123"/>
<body>Hello World!</body>
+ <foo xmlns:a="a" a="1"
+ xmlns:b="b" b= "2"
+ xmlns:c="c" c ="3" />
<test:body xmlns:test="http://example.org/test">Test Text ....</test:body>
</foo>

0 comments on commit 3d3ec87

Please sign in to comment.