diff options
| author | Valery Febvre <vfebvre at easter-eggs.com> | 2004-04-14 16:46:30 +0000 |
|---|---|---|
| committer | Valery Febvre <vfebvre at easter-eggs.com> | 2004-04-14 16:46:30 +0000 |
| commit | 8242ff6cecf29f55f8e4a9134f427ff3667f432d (patch) | |
| tree | 7c979f2247849bdbc783504d5f6f37f9f5c71b8c | |
| parent | 2b8c7f226d881da7eea85fb197f03000ae2f0101 (diff) | |
Added public method lasso_node_parse_memory()
| -rw-r--r-- | lasso/xml/xml.c | 120 | ||||
| -rw-r--r-- | lasso/xml/xml.h | 15 |
2 files changed, 81 insertions, 54 deletions
diff --git a/lasso/xml/xml.c b/lasso/xml/xml.c index a4e4e87c..5333a8bc 100644 --- a/lasso/xml/xml.c +++ b/lasso/xml/xml.c @@ -116,6 +116,14 @@ lasso_node_get_name(LassoNode *node) } void +lasso_node_parse_memory(LassoNode *node, + const char *buffer) +{ + LassoNodeClass *class = LASSO_NODE_GET_CLASS(node); + class->parse_memory(node, buffer); +} + +void lasso_node_rename_prop(LassoNode *node, const xmlChar *old_name, const xmlChar *new_name) @@ -284,6 +292,44 @@ lasso_node_impl_build_query(LassoNode *node) return (query); } +static void +lasso_node_impl_dump(LassoNode *node, + const xmlChar *encoding, + int format) +{ + xmlChar *ret; + int len; + xmlOutputBufferPtr buf; + xmlCharEncodingHandlerPtr handler = NULL; + + if (encoding != NULL) { + handler = xmlFindCharEncodingHandler(encoding); + if (handler == NULL) { + return; + } + } + buf = xmlAllocOutputBuffer(handler); + if (buf == NULL) { + return; + } + xmlNodeDumpOutput(buf, node->private->node->doc, node->private->node, + 0, format, encoding); + xmlOutputBufferFlush(buf); + if (buf->conv != NULL) { + len = buf->conv->use; + ret = buf->conv->content; + buf->conv->content = NULL; + } + else { + len = buf->buffer->use; + ret = buf->buffer->content; + buf->buffer->content = NULL; + } + (void) xmlOutputBufferClose(buf); + + printf("%s\n\n", ret); +} + static LassoAttr* lasso_node_impl_get_attr(LassoNode *node, const xmlChar *name) { @@ -371,42 +417,32 @@ lasso_node_impl_get_name(LassoNode *node) return ((xmlChar *)(node->private->node->name)); } +void +lasso_node_impl_parse_memory(LassoNode *node, + const char *buffer) +{ + xmlDocPtr doc; + xmlNodePtr root; + + doc = xmlParseMemory(buffer, streln(buffer)); + root = xmlDocGetRootElement(doc); + xmlFreeNode(node->private->node); + node->private->node = root; +} + static void -lasso_node_impl_dump(LassoNode *node, - const xmlChar *encoding, - int format) +lasso_node_impl_rename_prop(LassoNode *node, + const xmlChar *old_name, + const xmlChar *new_name) { - xmlChar *ret; - int len; - xmlOutputBufferPtr buf; - xmlCharEncodingHandlerPtr handler = NULL; + xmlChar *value; + LassoAttr *prop; - if (encoding != NULL) { - handler = xmlFindCharEncodingHandler(encoding); - if (handler == NULL) { - return; - } - } - buf = xmlAllocOutputBuffer(handler); - if (buf == NULL) { - return; - } - xmlNodeDumpOutput(buf, node->private->node->doc, node->private->node, - 0, format, encoding); - xmlOutputBufferFlush(buf); - if (buf->conv != NULL) { - len = buf->conv->use; - ret = buf->conv->content; - buf->conv->content = NULL; - } - else { - len = buf->buffer->use; - ret = buf->buffer->content; - buf->buffer->content = NULL; + value = xmlGetProp(node->private->node, old_name); + if (value != NULL) { + xmlRemoveProp(lasso_node_get_attr(node, old_name)); + lasso_node_set_prop(node, new_name, value); } - (void) xmlOutputBufferClose(buf); - - printf("%s\n\n", ret); } static GData * @@ -575,7 +611,7 @@ lasso_node_impl_verify_signature(LassoNode *node, return (ret); } -/*****************************************************************************/ +/*** private methods *********************************************************/ static void lasso_node_impl_add_child(LassoNode *node, @@ -634,21 +670,6 @@ lasso_node_impl_new_ns(LassoNode *node, } static void -lasso_node_impl_rename_prop(LassoNode *node, - const xmlChar *old_name, - const xmlChar *new_name) -{ - xmlChar *value; - LassoAttr *prop; - - value = xmlGetProp(node->private->node, old_name); - if (value != NULL) { - xmlRemoveProp(lasso_node_get_attr(node, old_name)); - lasso_node_set_prop(node, new_name, value); - } -} - -static void lasso_node_impl_set_name(LassoNode *node, const xmlChar *name) { @@ -725,6 +746,8 @@ lasso_node_class_init(LassoNodeClass *class) class->get_children = lasso_node_impl_get_children; class->get_content = lasso_node_impl_get_content; class->get_name = lasso_node_impl_get_name; + class->parse_memory = lasso_node_impl_parse_memory; + class->rename_prop = lasso_node_impl_rename_prop; class->serialize = lasso_node_impl_serialize; class->url_encode = lasso_node_impl_url_encode; class->verify_signature = lasso_node_impl_verify_signature; @@ -733,7 +756,6 @@ lasso_node_class_init(LassoNodeClass *class) class->get_xmlNode = lasso_node_impl_get_xmlNode; class->new_child = lasso_node_impl_new_child; class->new_ns = lasso_node_impl_new_ns; - class->rename_prop = lasso_node_impl_rename_prop; class->set_name = lasso_node_impl_set_name; class->set_node = lasso_node_impl_set_node; class->set_prop = lasso_node_impl_set_prop; diff --git a/lasso/xml/xml.h b/lasso/xml/xml.h index 9d7fe40f..aa837caa 100644 --- a/lasso/xml/xml.h +++ b/lasso/xml/xml.h @@ -73,7 +73,12 @@ struct _LassoNodeClass { const xmlChar *); GPtrArray* (* get_children) (LassoNode *); xmlChar * (* get_content) (LassoNode *); + void (* parse_memory) (LassoNode *node, + const char *buffer); xmlChar * (* get_name) (LassoNode *); + void (* rename_prop) (LassoNode *node, + const xmlChar *old_name, + const xmlChar *new_name); GData * (* serialize) (LassoNode *, GData *); gchar * (* url_encode) (LassoNode *node, @@ -93,9 +98,6 @@ struct _LassoNodeClass { void (* new_ns) (LassoNode *, const xmlChar *, const xmlChar *); - void (* rename_prop) (LassoNode *node, - const xmlChar *old_name, - const xmlChar *new_name); void (* set_name) (LassoNode *, const xmlChar *); void (* set_node) (LassoNode *, @@ -122,11 +124,11 @@ LASSO_EXPORT void lasso_node_dump (LassoNode *, LASSO_EXPORT LassoAttr* lasso_node_get_attr (LassoNode *node, const xmlChar *name); -LASSO_EXPORT GPtrArray* lasso_node_get_attrs (LassoNode *node); - LASSO_EXPORT xmlChar* lasso_node_get_attr_value (LassoNode *node, const xmlChar *name); +LASSO_EXPORT GPtrArray* lasso_node_get_attrs (LassoNode *node); + LASSO_EXPORT LassoNode* lasso_node_get_child (LassoNode *node, const xmlChar *name); @@ -136,6 +138,9 @@ LASSO_EXPORT xmlChar* lasso_node_get_content (LassoNode *node); LASSO_EXPORT xmlChar* lasso_node_get_name (LassoNode *node); +LASSO_EXPORT void lasso_node_parse_memory (LassoNode *node, + const char *buffer); + LASSO_EXPORT void lasso_node_rename_prop (LassoNode *node, const xmlChar *old_name, const xmlChar *new_name); |
