Skip to content

Commit 16c59a4

Browse files
committed
xml: Correctly find the first child element
1 parent 8e322e4 commit 16c59a4

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

include/crm/common/xml.h

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,16 +315,34 @@ __xml_next(xmlNode * child)
315315
return child;
316316
}
317317

318+
static inline xmlNode *
319+
__xml_first_child_element(xmlNode * parent)
320+
{
321+
xmlNode *child = NULL;
322+
323+
if (parent) {
324+
child = parent->children;
325+
}
326+
327+
while (child) {
328+
if(child->type == XML_ELEMENT_NODE) {
329+
return child;
330+
}
331+
child = child->next;
332+
}
333+
return NULL;
334+
}
335+
318336
static inline xmlNode *
319337
__xml_next_element(xmlNode * child)
320338
{
321-
if (child) {
339+
while (child) {
322340
child = child->next;
323-
while (child && child->type != XML_ELEMENT_NODE) {
324-
child = child->next;
341+
if(child && child->type == XML_ELEMENT_NODE) {
342+
return child;
325343
}
326344
}
327-
return child;
345+
return NULL;
328346
}
329347

330348
void free_xml(xmlNode * child);

0 commit comments

Comments
 (0)