2 * Copyright (C) 2007 Martin Willi
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 #include <libxml/parser.h>
21 #include <libxml/tree.h>
24 typedef struct private_xml_t private_xml_t
;
29 struct private_xml_t
{
37 * root node of this xml (part)
42 * document, only for root xml_t
52 * number of enumerator instances
58 * child element enumerator
61 /** enumerator interface */
63 /** current child context (returned to enumerate() caller) */
65 /** currently processing node */
69 METHOD(enumerator_t
, child_enumerate
, bool,
70 child_enum_t
*e
, private_xml_t
**child
, char **name
, char **value
)
72 while (e
->node
&& e
->node
->type
!= XML_ELEMENT_NODE
)
74 e
->node
= e
->node
->next
;
80 text
= e
->node
->children
;
83 while (text
&& text
->type
!= XML_TEXT_NODE
)
89 *value
= text
->content
;
91 *name
= (char*)e
->node
->name
;
93 e
->child
.node
= e
->node
->children
;
94 e
->node
= e
->node
->next
;
100 METHOD(xml_t
, get_attribute
, char*,
101 private_xml_t
*this, char *name
)
106 METHOD(enumerator_t
, child_destroy
, void,
109 if (--this->child
.root
->enums
== 0)
111 xmlFreeDoc(this->child
.root
->doc
);
112 free(this->child
.root
);
117 METHOD(xml_t
, children
, enumerator_t
*,
123 .enumerate
= (void*)_child_enumerate
,
124 .destroy
= _child_destroy
,
128 .get_attribute
= _get_attribute
,
129 .children
= _children
,
143 xml_t
*xml_create(char *xml
)
149 .get_attribute
= _get_attribute
,
150 .children
= _children
,
152 .doc
= xmlReadMemory(xml
, strlen(xml
), NULL
, NULL
, 0),
161 this->node
= xmlDocGetRootElement(this->doc
);
164 return &this->public;