|
XMLAPI XML * xml_search (XML * start, const char * element, const char * attr, const char * value)
{
int found = 0;
XML * cur = start;
XML * next = NULL;
if (!xml_is_element (start)) return NULL;
while (!found) {
found = 1;
if (element) {
if (!xml_is (cur, element)) found = 0;
}
if (found && attr) {
if (value) {
if (strcmp (value, xml_attrval (cur, attr))) found = 0;
}
else if (!*xml_attrval (cur, attr)) found = 0;
}
if (found) return cur;
next = xml_firstelem (cur); /* TODO: Make this an xml_nextdepthfirst. */
while (!next) {
if (!next) next = xml_nextelem (cur);
if (!next) {
/*if (cur == start || !cur) return NULL;*/
cur = xml_parent (cur);
if (cur == start || !cur) return NULL;
}
}
cur = next;
}
}
XMLAPI XML * xml_searchf (XML * start, const char * element, const char * attr, const char * format, ...);
XMLAPI XML * xml_search_next (XML * top, XML * start, const char * element, const char * attr, const char * value)
{
int found = 0;
XML * cur = start;
XML * next;
if (!xml_is_element (start)) return NULL;
while (!found) {
next = xml_firstelem (cur);
while (!next) {
if (!next) next = xml_nextelem (cur);
if (!next) {
if (cur == top || !cur) return NULL;
cur = xml_parent (cur);
}
}
cur = next;
found = 1;
if (element) {
if (!xml_is (cur, element)) found = 0;
}
if (found && attr) {
if (value) {
if (strcmp (value, xml_attrval (cur, attr))) found = 0;
}
else if (!*xml_attrval (cur, attr)) found = 0;
}
if (found) return cur;
}
}
XMLAPI XML * xml_searchf_next (XML * top, XML * start, const char * element, const char * attr, const char * format, ...);
|