ofXML iterating through element attributes

Anyone know how to iterate through an element’s attributes? I’m getting a bit stuck as xml.getAttributes returns a Range<ofXmlIteratorpugi::xml_attribute_iterator> and I have no idea how to iterate through that!

While we’re at it, how do I remove an element from the xml when I have a reference to that xml node (not the path name “node/subnode/mynode” etc)

any advice welcome!

to iterate you can simply do:

for(auto & attribute: xml.getAttributes()){

where attribute is just an ofXml::Attribute

There’s no method right now to remove having a node instead of the name, i’m going to add it and it should be on tomorrows nightly and 0.10.1 which will be released soon

Thanks Arturo, I did try that but I’m getting an error :

No matching construct for initialisation of 'ofXml'

Which seems to relate to line 82 (the “begin” definition) in ofXml.h :

class Range{
		It begin() const { return It(ofXml(doc, *range.begin())); }
		It end() const { return It(ofXml(doc, pugi::xml_node())); }

Is it a bug? I think Range is more commonly used for xml nodes, right?



mmh, yeah that sounds like a bug, we probably need a different class to iterate through attributes, let me look into it

Thanks Arturo, for now I’ve made the xml property of ofXml public so I can access the attributes directly from that, but let me know how you get along.