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
, va_list args
)
72 private_xml_t
**child
;
75 VA_ARGS_VGET(args
, child
, name
, value
);
77 while (e
->node
&& e
->node
->type
!= XML_ELEMENT_NODE
)
79 e
->node
= e
->node
->next
;
85 text
= e
->node
->children
;
88 while (text
&& text
->type
!= XML_TEXT_NODE
)
94 *value
= text
->content
;
96 *name
= (char*)e
->node
->name
;
98 e
->child
.node
= e
->node
->children
;
99 e
->node
= e
->node
->next
;
105 METHOD(xml_t
, get_attribute
, char*,
106 private_xml_t
*this, char *name
)
111 METHOD(enumerator_t
, child_destroy
, void,
114 if (--this->child
.root
->enums
== 0)
116 xmlFreeDoc(this->child
.root
->doc
);
117 free(this->child
.root
);
122 METHOD(xml_t
, children
, enumerator_t
*,
128 .enumerate
= enumerator_enumerate_default
,
129 .venumerate
= _child_enumerate
,
130 .destroy
= _child_destroy
,
134 .get_attribute
= _get_attribute
,
135 .children
= _children
,
149 xml_t
*xml_create(char *xml
)
155 .get_attribute
= _get_attribute
,
156 .children
= _children
,
158 .doc
= xmlReadMemory(xml
, strlen(xml
), NULL
, NULL
, 0),
167 this->node
= xmlDocGetRootElement(this->doc
);
170 return &this->public;