base: add Xml_node::for_each_attribute

Adds a function that allows iterating over an XML node's attributes
without relying on `Xml_node::Nonexistent_attribute`.

Issue #4817
This commit is contained in:
Timo Nicolai 2023-04-19 14:11:39 +02:00 committed by Christian Helmuth
parent 7e06aa13c1
commit 83f78e7fe6

View File

@ -990,6 +990,26 @@ class Genode::Xml_node
}
}
/**
* Execute functor 'fn' for each attribute
*/
template <typename FN>
void for_each_attribute(FN const &fn) const
{
if (!_tags.start.has_attribute())
return;
for (Xml_attribute attr = _tags.start.attribute(); ; ) {
fn(attr);
Token const next = attr._next_token();
if (!Xml_attribute::_valid(next))
return;
attr = Xml_attribute(next);
}
}
/**
* Return true if sub node of specified type exists
*/